self.tableview reloadData causing crash in UITableView

时光毁灭记忆、已成空白 提交于 2020-01-25 21:45:07

问题


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];
}

回答1:


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.




回答2:


 - (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.tableView reloadData];
}

Moving reloadData to viewDidAppear solves this issue.




回答3:


Since its happening while selecting a row, the error is most likely in your tableView:didSelectRowAtIndexPath: or tableView:willSelectRowAtIndexPath: method(s). Nothing seems intrinsically wrong with the viewWillAppear: code fragment that you've posted.



来源:https://stackoverflow.com/questions/3945842/self-tableview-reloaddata-causing-crash-in-uitableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!