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开发者_JS百科 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?
in viewdidload use this
[self performSelector:@selector(loadData) withObject:nil afterDelay:.5];
and then use your code inside loaddata method...
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;
}
精彩评论