self.tableview reloadData 导致 UITableView 崩溃
我在选择一行时遇到此崩溃:'-[__NSCFArray objectAtIndex:]: index (1)超出边界(1)',
我将数据移出了viewWillAppear,因为我们认为它导致了崩溃。我现在已将其加载到 ViewDidLoad 上。
但是如果 [self.tableview reloadData];开启后,我遇到了这个崩溃。
有想法吗?
-(void) loadData3;{
MyAppDelegate *AppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.tableDataSource3 = [AppDelegate.data3 objectForKey:@"Rows"];
NSLog(@"AppDelegate.data3 : %@",AppDelegate.data3 );
NSLog(@"self.tableDataSource3 : %@",self.tableDataSource3 );
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData3];
if(CurrentLevel3 == 0) {
self.navigationItem.title = @"Families I Follow";
}
else
self.navigationItem.title = CurrentTitle3;
}
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
[self.tableview reloadData];
}
I'm getting this crash when selecting a row: '-[__NSCFArray objectAtIndex:]: index (1) beyond bounds (1)',
I moved the data out of the viewWillAppear because we though it was causing a crash. I now have it loading on ViewDidLoad.
However if the [self.tableview reloadData]; is on, I get this crash.
Ideas?
-(void) loadData3;{
MyAppDelegate *AppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.tableDataSource3 = [AppDelegate.data3 objectForKey:@"Rows"];
NSLog(@"AppDelegate.data3 : %@",AppDelegate.data3 );
NSLog(@"self.tableDataSource3 : %@",self.tableDataSource3 );
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData3];
if(CurrentLevel3 == 0) {
self.navigationItem.title = @"Families I Follow";
}
else
self.navigationItem.title = CurrentTitle3;
}
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
[self.tableview reloadData];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很可能,您正在更改显示 UITableView 时加载 UITableView 的数组,因此当您单击行时,该行不再存在于数组中。因此,数组上出现越界错误。
More than likely, you are changing the Array that loads the UITableView while it is being displayed, so when you click on a Row the row no longer exists in the Array. Therefore, the out of bounds error on the Array.
将
reloadData
移动到viewDidAppear
可以解决此问题。Moving
reloadData
toviewDidAppear
solves this issue.由于它是在选择行时发生的,因此该错误很可能出现在您的
tableView:didSelectRowAtIndexPath:
或tableView:willSelectRowAtIndexPath:
方法中。您发布的viewWillAppear:
代码片段似乎没有本质上的错误。Since its happening while selecting a row, the error is most likely in your
tableView:didSelectRowAtIndexPath:
ortableView:willSelectRowAtIndexPath:
method(s). Nothing seems intrinsically wrong with theviewWillAppear:
code fragment that you've posted.