In my iPhone application I have two view controllers that I want to present modally. There is a root controller that presents the first one (say A), and then A presents the second one (say B). Then I want to dismiss both A and B at once, which I do by calling the dismiss…
method from the root controller. The documentation states that in this case the whole stack of controllers gets dismissed, both A and B. Both controllers really disappear from the screen, but when I inspect A, its modalViewController
property is still set and when I later try once more to present B from A, nothing happens. I solved this situation by calling dismissModalViewControllerAnimated:NO
on A befo开发者_如何学Gore I present A on screen, but that’s a hack, not a real solution. What’s going on, what am I doing wrong?
Hmm. I had no trouble in this situation.
I implemented this with a delegate and protocol, just a method dismissMe: in the parent which handled the dismissal, and a variable in the child to point back to the parent. When root set up A, it told A that root was its delegate; ditto when A set up B.
When B was done, it sent [delegate dismissMe:self]. A's dismissMe: dismissed B unanimated, then sent [delegate dismissMe:self]. Root's dismissMe: then dismissed A unanimated. The visible effect was B giving way right to root.
I can dig out source from my git repo if requested. I went to a different scheme when that app's workflow became more complex.
精彩评论