在我第一次加载时一切正常。这是我的 NSlog
2013-03-07 09:15:57.289 SAMPLE[10566:207] -->Starting viewDidLoad
2013-03-07 09:15:57.775 SAMPLE[10566:207] -->Starting viewDidAppear
2013-03-07 09:15:58.518 SAMPLE[10566:207] all done!
2013-03-07 09:15:58.518 SAMPLE[10566:207] stories array has 4 items
2013-03-07 09:15:58.527 SAMPLE[10566:207] -->Starting CellForRowAtIndex
但是当我单击导航中的后退按钮并再次单击 View 时,它会挂起,直到单元格被填充。请参阅下面的 NSlog
2013-03-07 09:16:06.252 SAMPLE[10566:207] -->Starting viewDidLoad
2013-03-07 09:16:06.309 SAMPLE[10566:207] -->Starting CellForRowAtIndex
2013-03-07 09:16:07.019 SAMPLE[10566:207] -->Starting CellForRowAtIndex
2013-03-07 09:16:07.679 SAMPLE[10566:207] -->Starting CellForRowAtIndex
2013-03-07 09:16:08.198 SAMPLE[10566:207] -->Starting CellForRowAtIndex
2013-03-07 09:16:09.242 SAMPLE[10566:207] -->Starting viewDidAppear
我的 viewDidAppear 中有以下内容。
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"-->Starting viewDidAppear");
[super viewDidAppear:animated];
if ([[xmlParser branch] count] == 0) {
[self loadDatafromServer]; // Goes and runs my XML Parser and fill the array.
}
[self loadBranchs]; // This just loads my annotations for my map
[self.tableView reloadData];
}
这里有任何想法。正如我所说,她第一次加载完美,但如果用户返回并进入,它会首先填充单元格,从而导致延迟。我希望它打开 View 然后填充。指示器将显示它们然后加载。
最佳答案
不要在 viewDidAppear 中实现该任务,因为此方法会在呈现 View 之前执行与其关联的其他任务。因此延迟。因此最好在 viewWillAppear 方法中实现它。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillDidAppear:animated];
if ([[xmlParser branch] count] == 0) {
[self loadDatafromServer]; // Goes and runs my XML Parser and fill the array.
}
[self loadBranchs]; // This just loads my annotations for my map
[self.tableView reloadData];
}
希望对你有帮助:)
关于iphone - 第二次尝试时,viewDidAppear 在 CellForRowAtIndex 之后加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15265363/