Cocoa Touch - dismissModalViewControllerAnimated:YES doesn't work
Hihi all,
Probably this is a fairly simple question, but I am new and just couldn't get it resolved. Okay, here is the problem:
- I have main view controller, in this controller's viewdidAppear delegate, I use
[self presentModalViewContr开发者_运维技巧oller animated:YES];
to show my second view. - In one of the method in my second view controller, it initiated the third controller for certain process.
- After the process in the third controller, it initiates again the second controller to call a method in the second controller. In this method, I use
[self dismissModalViewControllerAnimated:YES];
but the second view just refuses to dismiss.
Hope I am clear enough on my scenario. Please advice. Thanks in advance!
:)
@from the post:After the process in the third controller, it initiates again the second controller to call a method in the second controller.
This shows that you are initiating a new instance of secondViewController which don't have a modalViewController presented in it. You should call the dismissModalViewControllerAnimated for the instance in which you actually presented it.
Like below
Design your thirdViewController like this
@class SecondView;
@interface ThirdView : UIViewController {
SecondView *secondViewRefPointer;
}
@property (nonatomic, retain) SecondView * secondViewRefPointer;
@end
and
//While adding the third view from the secondView
ThirdView *thirdViewInstance = [[ThirdView alloc]init];
thirdViewInstance.secondViewRefPointer = self; //self will refer to the current secondView instance
…
And in third view call the dismissModalViewController as below
[secondViewRefPointer dismissModalViewControllerAnimated:YES];
As a hit and trial, just try first to call dismissModalViewControllerAnimated:YES through any button triggered action in your third view. If this works, use NSLog and check the sequence if methods called. This way you can figure out where exactly you should put your dismissModalViewControllerAnimated:YES.
Hope this helps.
精彩评论