iOS7中UITableView中cell的使用
2013-12-20 15:33
295 查看
转自http://m.blog.csdn.net/blog/wangyx810328/11751591
今天看到很多人提到,在iOS7中,使用UITableView的时候,对于cell要注意:[cell addSubview:userTextField] 这种用法不能再用了,应该使用 [cell.contentView addSubview:userTextField] 的方式。
如某人就遇到这种问题:
http://www.cocoachina.com/bbs/read.php?tid=153522
调查了一下原因:现在的UITableViewCell包含了一个scrollView。下面一个文章中也有介绍:
http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/ http://www.haogongju.net/art/2259666
UITableViewCell的定制。
以前可以直接继承UITableViewCell然后drawRect;
现在不行了,现在的UITableViewCell包含了一个scrollView,你重绘了UITableViewCell将会被这个scrollView遮住而完全没法显示.
解决思路:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:nil] autorelease];
UIView * subview = [[[XXView alloc] init] autorelease];
subview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
subview.backgroundColor = [UIColorclearColor];// 设为透明从而使得cell.backgroundColor有效.
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:subview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
return cell;
}
今天看到很多人提到,在iOS7中,使用UITableView的时候,对于cell要注意:[cell addSubview:userTextField] 这种用法不能再用了,应该使用 [cell.contentView addSubview:userTextField] 的方式。
如某人就遇到这种问题:
http://www.cocoachina.com/bbs/read.php?tid=153522
调查了一下原因:现在的UITableViewCell包含了一个scrollView。下面一个文章中也有介绍:
http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/ http://www.haogongju.net/art/2259666
UITableViewCell的定制。
以前可以直接继承UITableViewCell然后drawRect;
现在不行了,现在的UITableViewCell包含了一个scrollView,你重绘了UITableViewCell将会被这个scrollView遮住而完全没法显示.
解决思路:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:nil] autorelease];
UIView * subview = [[[XXView alloc] init] autorelease];
subview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
subview.backgroundColor = [UIColorclearColor];// 设为透明从而使得cell.backgroundColor有效.
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:subview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
return cell;
}
相关文章推荐
- 【iOS开发】关于UITableView的cell循环使用
- iOS -UITableView-FDTemplateLayoutCell 的使用
- iOS开发总结之项目开发中使用UITableView自定义多级表格&自定义cell
- IOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 【iOS】Masonry和FDTemplateLayoutCell搭配使用「UITableview自适应内容高度」
- ios-day07-02(模仿新浪微博:UITableView中cell的高度不一致,使用代码来自定义cell、UITableViewController的使用)
- iOS 之 UITableView 使用详解/性能优化/UITableViewCell/UITableViewController
- iOS:在UITableView里使用自定义Cell的那点事(简要总结)
- [IOS]UITableView重用(使用多个自定义Cell)
- iOS UITableView Cell动态高度(使用AutoLayout)
- iOS UITableView使用reloadData刷新后TableViewCell向上偏移问题
- iOS 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- iOS Uitableview的cell的选中样式
- ios UITableview 刷新某一个cell 或 section
- ios UITableView中Cell的重用机制
- 使用UITableView+FDTemplateLayoutCell计算cell的高度
- iOS7中UITableView中cell的使用
- iOS之UITableView Cell重用机制