美文网首页SB Cell
【开发笔记】自定义Cell的那些事

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

作者: oriyum | 来源:发表于2016-03-15 13:42 被阅读43次

自定义单选的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]];

效果图如下

QQ20160315-0@2x.png

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

相关文章

网友评论

    本文标题:【开发笔记】自定义Cell的那些事

    本文链接:https://www.haomeiwen.com/subject/ybfqlttx.html