views:

430

answers:

2

Hi,

What prevents a modal view controller from being dismissed? I've found dismissModalViewControllerAnimated doesn't always work? For example this won't work:

SettingsViewController* settings = [[SettingsViewController alloc] init];
UINavigationController *settingsNav = [[UINavigationController alloc] initWithRootViewController:settings];
[navigationController presentModalViewController:settingsNav animated:YES];     
[navigationController dismissModalViewControllerAnimated:YES];

Thanks!

+2  A: 

If you try to do too many navigation animations too close together, they usually won't work. Try doing your dismissModalViewControllerAnimated: after a delay of 0.75 seconds.

Ben Gottlieb
A: 
SettingsViewController* settings = [[SettingsViewController alloc] init];
UINavigationController *settingsNav = [[UINavigationController alloc] initWithRootViewController:settings];
[navigationController presentModalViewController:settingsNav animated:YES]; 
[settingsNav dismissModalViewControllerAnimated:YES];

If SettingsViewController it's UIViewController then:

SettingsViewController* settings = [[SettingsViewController alloc] init];
[self presentModalViewController:settings animated:YES]; 
[settings dismissModalViewControllerAnimated:YES];
sakrist