开发者

viewcontroller won't dismiss

I have the following code

- (void) viewWillAppear:(BOOL)animated
{
   NSLog(@"dismiss view");
   [self 开发者_运维问答dismissModalViewControllerAnimated:YES];
}

This prints dismiss view but won't execute the view dismissal code.

Can a view be dismissed in code without a trigger from an IBAction?

Why wouldn't this be executing?


You would probably have better luck putting the code into viewDidAppear rather than viewWillAppear. The latter tends to be called right at the start of any animation such as a modal beginning to slide off the screen; the former tends to be called when that animation has completely finished. Note that even if this strategy works, you may end up with a weird effect whereby two modals are seen to slide off, one after the other; I presume you just want one sliding off effect.

What happens if you dismiss the "lower down" modal dialog (the one first pushed), and don't bother dismissing the one that is topmost?

Also consider paying attention to the animated argument when dismissing your modal view controller. Different combinations of animated or not can have different effects when you have problems like yours.

If you post a more complete code sample we can give a better answer!


try with a little delay on the second dismiss.

- (void) viewWillAppear:(BOOL)animated
{
   NSLog(@"dismiss view");
   [self performSelector:@selector(delayedDismiss) withObject:nil afterDelay:0.5];
}

-(void)delayedDismiss{
   [self dismissModalViewControllerAnimated:YES];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜