iOS 根视图控制器的 viewDidAppear:在启动屏幕(Default.png)仍在屏幕上时调用

发布于 2024-11-04 05:27:17 字数 184 浏览 0 评论 0原文

在我的 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 技术交流群。

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

发布评论

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

评论(2

原谅过去的我 2024-11-11 05:27:17

在 viewdidload 中使用它

[self performSelector:@selector(loadData) withObject:nil afterDelay:.5];

,然后在 loaddata 方法中使用你的代码......

in viewdidload use this

[self performSelector:@selector(loadData) withObject:nil afterDelay:.5];

and then use your code inside loaddata method...

嘿嘿嘿 2024-11-11 05:27:17

我自己刚刚遇到了一个非常类似的问题,其中我想在加载根视图控制器后显示模式登录视图。我以前一直使用 viewDidAppear,但当我升级到 iOS 4.3 SDK 时,该行为中断了。

我通过从应用程序委托的 application:didFinishLaunchingWithOptions: 选择器调用根视图控制器上的选择器来修复此问题。像另一个答案一样使用延迟有点麻烦,而且可能并不完全可靠。

yourAppDelegate.m 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Add the view controller's view to the window and display.
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    // Invoke operations here. For example, show login view:
    [viewController showModalLoginView];

    return YES;
}

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:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Add the view controller's view to the window and display.
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    // Invoke operations here. For example, show login view:
    [viewController showModalLoginView];

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