xib 自定义cell

1.cell点击效果————cell的框变颜色/xib自定义cell,重用池

<pre name="code" class="objc">-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"ManageTableViewCell";
    ManageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ManageTableViewCell" owner:self options:nil];
    if (!cell) {
        for (id view in nibs) {
            if ([view isKindOfClass:[ManageTableViewCell class]]) {
                cell = view;
            }
        }
    }

        cell.target = self;
        cell.changeButtonAction = @selector(changeButtonAction:);
        cell.changeBtn.tag = indexPath.row + 1;
    
        cell.editButtonAction = @selector(editButtonAction:);
        cell.editBtn.tag = indexPath.row + 1000;
        
        cell.clearButtonAction = @selector(clearButtonAction:);
        cell.clearBtn.tag = indexPath.row + 2000;
        cell.nameLabel.text = @"大黑牛";
        cell.phoneLabel.text = @"15534598900";
        cell.addressLabel.text = @"大空间的开发基地开工大连市高科技的时各家各户飞机和飞机和飞机高";
        cell.backgroundColor = [UIColor clearColor];
        //----------------自定义选中cell时的背景颜色
        UIView *selectedView = [[UIView alloc] initWithFrame:cell.background.frame];
        selectedView.backgroundColor = [UIColor whiteColor];
        selectedView.layer.borderColor = WORDS_COLOR.CGColor;
        selectedView.layer.borderWidth = 1;
        selectedView.layer.cornerRadius = 3;
        cell.selectedBackgroundView = selectedView;

    return cell;
}



2.cell上的按钮点击事件

@property (assign, nonatomic)SEL changeButtonAction;//修改默认
@property (assign, nonatomic)SEL clearButtonAction;//删除
@property (assign, nonatomic)SEL editButtonAction;//编辑
@property (assign, nonatomic)id target;

-(void)layoutSubviews{
    [self.changeBtn addTarget:self.target action:self.changeButtonAction forControlEvents:UIControlEventTouchUpInside];
    [self.clearBtn addTarget:self.target action:self.clearButtonAction forControlEvents:UIControlEventTouchUpInside];
//     [self.clearPic addTarget:self.target action:self.clearButtonAction forControlEvents:UIControlEventTouchUpInside];
    [self.editBtn addTarget:self.target action:self.editButtonAction forControlEvents:UIControlEventTouchUpInside];
//    [self.editPic addTarget:self.target action:self.editButtonAction forControlEvents:UIControlEventTouchUpInside];
    [self.changeBtn setBackgroundImage:[UIImage imageNamed:@"select_no.png"] forState:UIControlStateSelected];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值