iphone - 第二次尝试时,viewDidAppear 在 CellForRowAtIndex 之后加载

标签 iphone ios objective-c

在我第一次加载时一切正常。这是我的 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/

相关文章:

ios - opencv ios视频​​处理

ios - 未获取 Dropbox 中应用注册的 key

iphone - 停止滚动 ScrollView 中的最后一个对象

iphone - 最接近 XCode、Windows 上的 Objective-C(不是 Hackintosh),也许是界面构建器

ios - 单击表格 View 单元格上的按钮时如何获取 indexPath.row?

ios - 我应该调用 [super viewDidDisappear :animated]; at the beginning or at the end of viewDidDisappear:

ios - 升级到 iOS 7.1 SDK 后出错 - 不再允许精度损失的隐式转换

iphone - 单击按钮时使用不同参数调用 api,并将其传递到 iPhone 中行索引路径的单元格

iphone - 如何将 YouTube 整合到 iPhone 应用程序中

iphone - 需要上传二进制文件来测试应用内购买吗?