Question

When the UIViewController starts, I want to start another UIViewController immediately. This doesn't work:

-(void) awakeFromNib {
    UIViewController *newcontroller = [[[UIViewController alloc] init] autorelease];
    ...
    [self presentModalViewController:newcontroller animated:YES];
}

In order for this to work, I have to do afterDelay for a method, like so:

-(void) awakeFromNib {
    [self performSelector:@selector(startNewController) withObject:nil afterDelay:0.5];
    [super init];
}
-(void) startNewController {
    UIViewController *newcontroller = [[[UIViewController alloc] init] autorelease];
    ...
}

Is it possible to get it to work without delay?

Was it helpful?

Solution

Call startNewController in your viewDidAppear method instead, that happens because your viewController is not totally loaded when you try to present the modal viewController, so that's why it works when you wait.

OTHER TIPS

Practically, you should not plan your application architecture which forces you to do such implementations. Though, I can understand there are times where you have no way out..

I'd say: best solution for your case is to call your controller from

viewDidAppear

or

viewWillAppear

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top