我有一个表格视图,右侧有一个详细标签。此标签由我从 connectionDidFinishLoading 函数中的 JSON 调用填充的实体填充。问题是 cellFromRowAtIndexPath 函数在 connectionDidFinishLoading 函数之前触发,所以在我拉下重绘页面的屏幕之前,我看不到表视图中的值。我已经尝试在这两个函数的末尾刷新表格视图,但这似乎不起作用。有人可以告诉我为什么会发生这种情况以及如何解决它。


我有一个表格视图,右侧有一个详细标签。此标签由我从 connectionDidFinishLoading 函数中的 JSON 调用填充的实体填充。问题是 cellFromRowAtIndexPath 函数在 connectionDidFinishLoading 函数之前触发,所以在我拉下重绘页面的屏幕之前,我看不到表视图中的值。我已经尝试在这两个函数的末尾刷新表格视图,但这似乎不起作用。有人可以告诉我为什么会发生这种情况以及如何解决它。


Are you calling reloadData in the main thread? connectionDidFinishLoading sounds like it's running in a background thread.
您必须在 connectionDidFinishLoading 结束时重新加载表数据。两种方式:
首先:
[tableView reloadData];
第二:
NSArray* rows = [tableView indexPathsForVisibleRows];
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:rows withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
这应该这样做。所有 UI 更新和操作都必须从主线程执行
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
填充后,调用reloadDatatableView。