Iphone 第二次尝试时,ViewDid显示在CellForRowatinex之后

Iphone 第二次尝试时,ViewDid显示在CellForRowatinex之后,iphone,ios,objective-c,Iphone,Ios,Objective C,在我第一次加载时,一切都很好。这是我的日志 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

在我第一次加载时,一切都很好。这是我的日志

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
但是,当我在导航中单击“上一步”按钮并再次单击视图时,它将挂起,直到填充单元格。见下面的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];       
}

有什么想法吗。正如我所说,她第一次加载perfect,但如果用户返回并进入,它会首先填充单元格,导致延迟。我希望它打开视图,然后填充。指示器将显示它们,然后显示其加载情况。

不要在ViewDidDisplay中执行该任务,因为此方法在显示视图之前执行与其相关的其他任务。因此延迟。因此最好在ViewWillDisplay方法中执行该任务

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

希望它能帮助您:)

我想您需要实现ViewWillDisplay来代替ViewDidDisplay。您也在viewDidLoad中调用[self.tableView reloadData]吗?@GopeshGupta是的,我是,同样的问题。从viewDidLoad中删除该问题。@GopeshGupta同样的问题。谢谢您的反馈。不,如果我这样做。当我单击转到视图时,它将挂起,直到填充单元格。第一次和第二次。@SnakeBlisken…您在viewdidload和ViewWillAspect方法上执行的操作是什么?在viewdidload中,我只是加载地图视图坐标,而ViewWillAspect中没有任何内容。