Hua-Ying
Hua-Ying

Reputation: 3166

dismissModalViewControllerAnimated doesn't always work?

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!

Upvotes: 4

Views: 1715

Answers (2)

Volodymyr B.
Volodymyr B.

Reputation: 3441

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];

Upvotes: 1

Ben Gottlieb
Ben Gottlieb

Reputation: 85542

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.

Upvotes: 5

Related Questions