iOS 根视图控制器的 viewDidAppear:在启动屏幕(Default.png)仍在屏幕上时调用
在我的 iOS 应用程序中,我想在根视图控制器出现在屏幕上后运行一系列操作。然而,似乎iOS应用程序正在调用viewDidAppear,而启动屏幕(即显示Default.png图像)仍在屏幕上并且在根视图控制器布置在屏幕上之前。我也在 viewDidLoad 中尝试了相同的代码,并且遇到了同样的问题。如何强制代码仅在根视图控制器实际出现在屏幕上时运行?
In my iOS app I want to run a series of operations in my Root View Controller after it has already appeared on the screen. However, it seems that the iOS app is calling viewDidAppear while the splash screen (i.e. showing the Default.png image) is still on the screen and before the root view controller is laid out on the screen. I've tried the same code in viewDidLoad as well, and had the same problem. How can I force code to run only once the root view controller is actually on-screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 viewdidload 中使用它
,然后在 loaddata 方法中使用你的代码......
in viewdidload use this
and then use your code inside loaddata method...
我自己刚刚遇到了一个非常类似的问题,其中我想在加载根视图控制器后显示模式登录视图。我以前一直使用
viewDidAppear
,但当我升级到 iOS 4.3 SDK 时,该行为中断了。我通过从应用程序委托的
application:didFinishLaunchingWithOptions:
选择器调用根视图控制器上的选择器来修复此问题。像另一个答案一样使用延迟有点麻烦,而且可能并不完全可靠。在
yourAppDelegate.m
中:I just encountered a very similar problem myself, wherein I wanted to display a modal login view after my root view controller loaded. I'd previously been using
viewDidAppear
, but the behavior broke when I upgraded to the iOS 4.3 SDK.I fixed it by calling a selector on my root view controller from the app delegate's
application:didFinishLaunchingWithOptions:
selector. Using a delay as in the other answer is a bit of a kludge, and probably not entirely reliable.In
yourAppDelegate.m
: