关于tableview的一些bug
2015-03-24 18:39
246 查看
about tableview bug
内存压力而奔溃
原因:cell没有被复用
一般来说,对于cell的复用是这样子的:
关于cell的复用:这里根据屏幕的高度,先创建第一个cell,第二个cell。当tabbleview向上滑动的时候,第一个cell渐渐移除屏幕,创建第三个cell,从屏幕下方进入显示。当第一个cell全部移除屏幕的时候会进入复用池,第四个cell就会复用第一个cell。这里tablveiw会创建3个cell,然后其他的就会复用。
(1)cell xib上的设置
(2)代码里面设置表的cell,给cell添加identifier,cell xib和这个identifier要一致
可我的问题是:
可是,我的代码里面这样子写,cell并没有复用,而是每次都创建了新的cell,每次都会进入if(cell==nil)里面去创建新的cell。
原因:StarShowTableViewCell
*cell = [starTableView
dequeueReusableCellWithIdentifier:identifier];
我用xib关联了一个starTableView,然后写了一个实例变量 uitableview
*starTableView;这里拿到的tableview和我显示tableview不是一样的。本来当前页面只有一个tableview,但是代码里面有两个了。
erminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray insertObject:range:: Out of bounds'
*** First throw call stack:
数组越界。cell复用,没有重置数据。没有刷新reloaddata
使用tableview的时候老是出现cell的数据重复,是因为我们复用cell却没有重置数据。就像tableview你给了他数据,还要reloaddata才行。
- (void)awakeFromNib
{
}
-(void)setStarModel:(StarShowModel
*)starModel{
_starModel = starModel;
}
-(void)layoutSubviews{
}
内存压力而奔溃
原因:cell没有被复用
一般来说,对于cell的复用是这样子的:
关于cell的复用:这里根据屏幕的高度,先创建第一个cell,第二个cell。当tabbleview向上滑动的时候,第一个cell渐渐移除屏幕,创建第三个cell,从屏幕下方进入显示。当第一个cell全部移除屏幕的时候会进入复用池,第四个cell就会复用第一个cell。这里tablveiw会创建3个cell,然后其他的就会复用。
(1)cell xib上的设置
(2)代码里面设置表的cell,给cell添加identifier,cell xib和这个identifier要一致
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"starShowCell"; StarShowTableViewCell *cell = [starTableView dequeueReusableCellWithIdentifier:identifier]; if (cell==nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StarShowTableViewCell" owner:nil options:nil]; for (id oneObject in nib) { if ([oneObject isKindOfClass:[StarShowTableViewCell class]]) { cell = (StarShowTableViewCell*)oneObject; } } } }
可我的问题是:
可是,我的代码里面这样子写,cell并没有复用,而是每次都创建了新的cell,每次都会进入if(cell==nil)里面去创建新的cell。
原因:StarShowTableViewCell
*cell = [starTableView
dequeueReusableCellWithIdentifier:identifier];
我用xib关联了一个starTableView,然后写了一个实例变量 uitableview
*starTableView;这里拿到的tableview和我显示tableview不是一样的。本来当前页面只有一个tableview,但是代码里面有两个了。
erminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray insertObject:range:: Out of bounds'
*** First throw call stack:
数组越界。cell复用,没有重置数据。没有刷新reloaddata
使用tableview的时候老是出现cell的数据重复,是因为我们复用cell却没有重置数据。就像tableview你给了他数据,还要reloaddata才行。
- (void)awakeFromNib
{
}
-(void)setStarModel:(StarShowModel
*)starModel{
_starModel = starModel;
}
-(void)layoutSubviews{
}
相关文章推荐
- 关于tableView滚动scroll的一些知识
- iOS 关于tableView cell的分割线的一些设置
- 一个关于tableView的footerView的子控件y 坐标的 BUG
- 关于用xib创建静态tableview可能会用到的一些委托函数
- iOS 关于tableView cell的分割线的一些设置
- 关于设置 UITableView 的 tableHeaderView为使用了 SnapKit 约束的自定义 view 时出现的 BUG 的处理
- 关于viewpager里Fragment嵌套Fragment的一些列bug解决
- 关于tableView的一些优化
- iOS 关于tableView cell的分割线的一些设置
- iOS 关于tableView 的一些记录
- 关于tableview 的一些属性设置
- 关于CCMultiColumnTableView一些小问题的修改
- 关于TableView Cell的一些设置
- iOS 关于tableView cell的分割线的一些设置
- 关于用xib创建静态tableview可能会用到的一些委托函数
- iOS学习笔记2—关于tableView的一些简单操作
- 关于tableview中cell的一些加载
- 关于10gR2(10.2.0.1)clusterware的bug修复方法和对CRS进程的一些理解
- 关于10gR2(10.2.0.1)clusterware的bug修复方法和对CRS进程的一些理解
- 关于later discovery bug的一些想法