tableViewCell的contentView和直接addS

2016-08-04  本文已影响379人  健尐
在自定义UITableViewCell,需要给它增加子视图
static NSString *cellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
  cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellID];
}
##需要给cell添加子视图,你会选择哪种:
  1.  [cell addSubview:子视图];
  2.  [cell.contentView addSubview:子视图];
子视图是一个红色的UILabel,字体随便
在表视图普通模型下,他们没有区别,如图
Simulator Screen Shot 2016年8月4日 14.40.39.png
在表视图编辑模型下,1没有变化, 2右移了,如图
Simulator Screen Shot 2016年8月4日 14.40.41.png
代码下载:https://github.com/y77087758/tableViewCell_addSubview
上一篇 下一篇

猜你喜欢

热点阅读