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?
1555 次
2 に答える
2
viewdidloadでこれを使用します
[self performSelector:@selector(loadData) withObject:nil afterDelay:.5];
次に、loaddataメソッド内でコードを使用します...
于 2011-04-29T09:19:44.410 に答える
2
ルートビューコントローラーがロードされた後にモーダルログインビューを表示したいという、非常によく似た問題に遭遇しました。以前は を使用して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;
}
于 2011-06-30T19:46:51.803 に答える