关于这个我的头发。
我的 tableview 突然停止加载数据。
我在 numberOfRowsInSection
和 cellForRowAtIndexPath
中设置了断点。 numberOfRowsInSection
就像
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [objects count];
}
由于某种原因被调用三次,当 View 最初加载时 objects
数组中的对象数为 0,这可以理解,因为 tableview 最初没有任何数据。
在我从服务器获取数据并将这些对象存储在我的 objects
数组中并调用 [self.tableView reloadData];
之后,numberOfRowsInSection
再次调用 objects
数组中的对象数量,这次是 46,但由于某种原因它仍然没有继续并输入 cellForRowAtIndexPath
。
我已经尝试在主线程上重新加载数据 -
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
没用。
我检查了所有的拼写。
当我重新加载数据时,检查我的 UITableView
对象不是 nil。
tableview的frame在viewDidLoad
中是320.0000*568.0000。
不知道出了什么问题。而且我假设我破坏了一些东西,因为数据早些时候加载得很好。
最佳答案
我假设您正在从另一个 View 加载 View ,那么您应该在 ViewDidLoad 上调用 [tableView reloadData] 并在那里更新数据源数组。这是因为 View 生命周期 - 当您从一个 View 返回并且您的 tableView 数据源已更新时, View 生命周期将是这样的:
- viewDidLoad
- tableViewDelegateMethods
- viewDidAppear
因此当您更新 tableView 的数据源对象并在 viewDidLoad 期间调用 reloadData 将解决问题。
关于ios - 即使 numberOfRowsInSection 中的 [objects count] 显示 46 个对象,也不会调用 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35170097/