ios tableView那些事 (十五)用故事模式自定义cell

如果想更灵活的添加一些数据我们常常自定义一个cell


先创建个工程 勾选sb 和arc  







把默认的里面的viewcontr 删除,拖拽个tableviecontr





创建一个TableViewControllerTest  一个类,这时候我们要把 拖拽的视图和这个新建的类关联上




接下来我们新建一个继承 uitableviewcell 的类  celltest



下面我们吧这个类跟tableview关联上

点击视图上面的cell 并把新建的cell关联上!  如图在custom class 下面选择CellTest










把cell 的格式选择Custom     把Identifier 改成你cell 的类名




然后让我们托几个label吧



在tableview上在加几行代码就搞定了



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier =@"cell";

    

   //CellTest *cell =  (CellTest *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    CellTest *cell = (CellTest *)[tableViewdequeueReusableCellWithIdentifier:@"CellTest"];

    if (cell == nil) {

        cell = [[CellTestalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier];

    }

    cell.label_one.text =@"one";

    cell.label_second.text =@"second";

    cell.labelthree.text =@"three";

    

    

    return cell;

}



   ///14 年5.10///

 自定义一个tableview 后不显示数据,我排查了连接 委托是否有问题后,发现一切正常,后来看了下代码,发现我copy 的标识符GoodsCarTableViewCell 后面有了一个

 空格,我把空格除去果断出现想要的数据,真是马虎呀。

 GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView    dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell  此处有空格 "];  错误 


正确

 GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView    dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell"];  后面无空格正确。

   ///14 年5.10///




  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值