苹果手机;只有在视图出现后才能执行操作..ViewWillAppear?

时间:2010-12-02 09:46:47

标签: iphone objective-c uiview

你好 我遇到了一些与此有关的困惑;我想在视图出现后才执行某些操作,可能在收集数据时显示活动指示。 我已经在viewWillAppear中编写了我的代码,但它似乎是在视图出现在屏幕上之前触发的。 我已经用一些NSLog语句对此进行了双重检查,并且我在viewWillAppear中添加了2秒的睡眠,NSLog语句被触发,并且视图仅在延迟2秒后出现 - 我预计,一旦视图执行了2秒延迟进入屏幕?

我做错了吗? 我甚至尝试过viewDidAppear,同样的事情。有什么建议吗?

由于

编辑:我想清楚地说明我在做什么

1. i have a parent view, which has a scroll view - and a subview
2. In the parent view, i create multiple instances of the subview and add them to the scrollview, creating scrollable views, which work.
3. Each view is passed an argument and depending on the argument the view contents change - works as expected.
4. I would like to show the subview and once its on the screen, do some internet opearations while i show an activity indicator, for this i need to use viewDidApper.
5. I am manually firing the subview's viewDidAppear from the parent view, once i have created its instance

这里的问题是,只有在所有操作完成后才会出现视图。

我该如何对此进行排序?

2 个答案:

答案 0 :(得分:5)

viewWillAppear应该在视图出现之前触发,因此名称中的单词。您可能对viewDidAppear感兴趣。

答案 1 :(得分:1)

我想我想出来了 - 我没有在viewDidAppear上执行操作,而是使用了performSelector,类似这样的

-(void) viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self performSelector:@selector(loadXML:) withObject: self afterDelay:0];

}

谢谢你们!