Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

xcode - Application tried to present modally an active controller

I have searched for and found various q/a on this error, but have not been able to find any specific help for my issue (at least that my minimal experience allows me to understand).

I am loading a UIView from the app's main menu, which in turn has several button options (call it submenu). One of these goes back to the main menu without issue ([self dismissModalViewControllerAnimated:YES]; ). Another button loads a UITableView (separate view controller), which loads fine. However, I want a button within this UITableView to go back to the submenu. When I use the above mentioned code, it goes all of the way back to the main menu. I can't seem to find a way to create an action that goes back to the submenu UIView (submenu).

When I try to do a standard ['uitableviewcontrollername' presentModalViewController:submenuView animated:YES]; I get the error Application tried to present modally an active controller (I get the same error if I replace uitableviewcontrollername with self.

The error makes sense in that I understand that it is already active, but what I need help with is, what exactly is the proper way to do what I've described above? Thanks for your time.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe the proper way to dismiss a modal view is to use delegation as defined in here.

In practice you define a method on the 'menu view' that will dismiss the active modal view by calling the usual :

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

You call it from the menu view but it will close the active modal on top of it. Then you define a delegate property on the modal table view controller, set it to the instance of the menu view, and in the method that closes the table view you call :

[delegate notifytoclose];

The use of [self dismissModalViewControllerAnimated:YES] to close the current instance is not always working although the circumstances are not clear to me. I also noticed differences between iPAd and iPhone behaviour.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...