首先,必须知道现在整个APP最顶层的ViewController是哪个,我的做法是在每个ViewController的viewWillAppear中记录一下,当然这个操作是自动完成的,因为每个项目,我都会从UIViewController派生一个子类,然后再从这个子类派生所有的ViewController方便管理.
@interface MMViewController : UIViewController
@end
@implementation MMViewController
- (void)viewWillAppear:(BOOL)animated
{
APP.presentingController = self;
}
@end
if( APP.presentingController)
{
UIViewController *vc = self.presentingController;
if( !vc.presentingViewController)
{
return;
}
while(vc.presentingViewController)
{
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:^{
}];
}
网友评论