【开发笔记】自定义Cell的那些事

自定义单选的TableView

TableView的代理方法里面

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DFCPlaceOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:[DFCPlaceOrderCell cellIdentify]];
    if (_lastIndexPath && _lastIndexPath == indexPath) {
        cell.selectImageView.image = [UIImage imageNamed:@"order_booking_selected"];
    }else{
        cell.selectImageView.image = [UIImage imageNamed:@"order_booking"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger newRow = [indexPath row];
    NSInteger oldRow = _lastIndexPath == nil ? -1 : _lastIndexPath.row;
    if (newRow != oldRow) {
        DFCPlaceOrderCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        DFCPlaceOrderCell *OldCell = [tableView cellForRowAtIndexPath:_lastIndexPath];
        cell.selectImageView.image = [UIImage imageNamed:@"order_booking_selected"];
        OldCell.selectImageView.image = [UIImage imageNamed:@"order_booking"];
        _lastIndexPath = indexPath;
    }
  }

viewDidLoad方法里面

self.tbView.frame = CGRectMake(0, 108 , sc_screenSize.width, sc_screenSize.height - 108);
[self.tbView registerClass:[DFCPlaceOrderCell class] forCellReuseIdentifier:[DFCPlaceOrderCell cellIdentify]];

效果图如下

【持续更新】欢迎提出开发中关于TableView相关的问题。

你可能感兴趣的:(【开发笔记】自定义Cell的那些事)