【开发笔记】自定义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]];

效果图如下

QQ20160315-0@2x.png

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,930评论 25 708
  • 序 本文简单介绍一下,在springboot中怎么个性化404错误信息。 返回json 然后定义个404的requ...
    go4it阅读 409评论 0 1
  • CSS基础 CSS介绍 层叠样式表 (Cascading Style Sheets,常缩写记作 CSS), 是一种...
    从这到那阅读 767评论 0 1
  • 截屏的暗恋将那段暗恋缀入雀跃再嵌入无节奏的心跳频率截成屏保存在记忆的云盘化作儿时的糖果寄给甜密的辛酸
    上山亩教育阅读 156评论 0 0