0

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?

zx81
  • 41,100
  • 9
  • 89
  • 105
blinsky
  • 3
  • 1

2 Answers2

0

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.

Youssef
  • 3,582
  • 1
  • 21
  • 28
0

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

Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41
  • I'll try to explain the need for such implementation. The root controller acts as a loader with "Download", etc. It will be shown while the other controller with graphics is loaded that performs the function menu. When choosing a menu item, I unload the current controller and run through the root controller the new one. Hope explained clearly. – blinsky Sep 22 '11 at 10:54