iPhone;仅在视图出现后才执行操作..ViewWillAppear?

发布于 2024-10-05 18:53:40 字数 964 浏览 1 评论 0原文

你好呀 我遇到了一些与此相关的困惑;我只想在视图出现后执行一些操作,可能在收集数据时显示活动指示器。 我已经在 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

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

我该如何排序?

Hi there
I ran into some confusion related to this; i would like to perform some actions only once the view is appeared, probably showing an activity indicator while the data is being collected.
I have written my code in viewWillAppear, but it seems to be firing before the view appears on the screen.
I have double checked this with some NSLog statements, and i added a sleep of 2 seconds in viewWillAppear, the NSLog statements get fired, and the view appears only after 2 seconds delay - i was expected, the 2 second delay is executed once the view comes onto the screen?

Am i doing something wrong?
I even tried viewDidAppear, same thing. Any suggestions?

Thanks

edit: I would like to give a clear scenario of what i am doing

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

The problem here is, the view is appearing only once all the operations are complete.

How can i sort this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

随心而道 2024-10-12 18:53:41

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

viewWillAppear is supposed to fire BEFORE the view appears, hence the word Will in the name. You might be interested in viewDidAppear.

霊感 2024-10-12 18:53:41

我想我已经明白了 -
我没有在 viewDidAppear 上执行操作,而是使用了 PerformSelector,类似这样的东西

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

}

谢谢大家!

I guess i figured it out -
Rather than performing operations on viewDidAppear, i used performSelector, something like this

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

}

Thanks guys!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文