UITableView 滚动时使用reloaddata出现 crash'-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (0)' Crash
2013-10-25 16:33
162 查看
例子:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndentifier = @"Account";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//adjust the height for cell
CGRect cellFrame = [cell frame];
cellFrame.size.height = self.bgImageView.frame.size.height/2;
//first time load the content
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
。。。。。。。。。
}
else
{
//这里主要是为了在滚动屏幕时候解决屏幕内容显示错误。但是却引发了这个问题,操作为向一个方向快速反复滚动就很容易crash,应该是reload后因为使用了dequeueReusableCellWithIdentifier导致table
无法得到正确的应当显示的cell内容和个数,导致出错。
[viewtable reloadData];
]
}
}
解决方法:
static NSString *CellIndentifier = @"Account";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//adjust the height for cell
CGRect cellFrame = [cell frame];
cellFrame.size.height = self.bgImageView.frame.size.height/2;
//first time load the content
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
//创建所有的子视图
}else
{
//移除所有的子视图
while ([cell.contentView.subviews lastObject] != nil)
{
[(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
}
//重新添加子视图
}
这样做的效果上看不会因为删除子视图然后出现空白等待加载的不良效果
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIndentifier = @"Account";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//adjust the height for cell
CGRect cellFrame = [cell frame];
cellFrame.size.height = self.bgImageView.frame.size.height/2;
//first time load the content
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
。。。。。。。。。
}
else
{
//这里主要是为了在滚动屏幕时候解决屏幕内容显示错误。但是却引发了这个问题,操作为向一个方向快速反复滚动就很容易crash,应该是reload后因为使用了dequeueReusableCellWithIdentifier导致table
无法得到正确的应当显示的cell内容和个数,导致出错。
[viewtable reloadData];
]
}
}
解决方法:
static NSString *CellIndentifier = @"Account";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
//adjust the height for cell
CGRect cellFrame = [cell frame];
cellFrame.size.height = self.bgImageView.frame.size.height/2;
//first time load the content
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease];
//创建所有的子视图
}else
{
//移除所有的子视图
while ([cell.contentView.subviews lastObject] != nil)
{
[(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
}
//重新添加子视图
}
这样做的效果上看不会因为删除子视图然后出现空白等待加载的不良效果
相关文章推荐
- 详谈Objective-C内存管理机制
- object-c之继承
- 如何在 Windows上编译Objective-C
- objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )
- 在SQL查询分析器中执行对SYSOBJECTS 操作的语句时提示:未启用对系统目录的特殊更新等信息
- Easier Windows Event Multiplexing on Waiting for Multiple Objects
- Objective-C中nil与release的区别与用法
- windows利用GNU下编写object-c程式
- blocks在Objective-C中是怎么工作的?
- Windows环境下面搭建Object C开发环境[转]
- mutating method sent to immutable object NSUserDefaults出错
- Objective C for Windows
- object-c学习1
- 通用对象池ObjectPool的一种简易设计和实现方案
- object-c内存管理
- Objective-C头文件导出工具class-dump
- Objective-C头文件导出工具class-dump
- objectc 创建文件 每秒写入一次
- iOS培训objective-c——实例化对象
- safari 7.0 Object.freeze BUG