开发者

Immediately starting new UIViewController from a viewcontroller

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

-(void) awakeFromNib {
    UIViewController *newcontroller = [[[UIViewController alloc] init] autorelease];
    ...
    [self present开发者_如何学JAVAModalViewController: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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜