如何解除中间viewControllers并返回rootViewController

时间:2016-09-19 14:14:15

标签: ios objective-c

我有三个视图控制器,比如root,middle,last。我想从lastViewController返回rootViewController

我尝试过自定义委托和NSNotificationCenter。但是当回到middleViewController闪烁一秒钟时(它被viewWillDisappear调用)。 我正在使用presentViewController / dismissViewController而不是导航。我不希望middleViewController闪现。

我在rootViewCotroller中有以下代码:

-(void)viewDidLoad {

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(actionBackToRoot) name:@"BackToRoot" object:nil];

}

-(void)actionBackToRoot : (NSNotification *) notification{

NSDictionary *userInfo = notification.userInfo;

UIViewController *lastViewController = [userInfo objectForKey:@"viewController"];

[middleViewController dismissViewControllerAnimated:NO completion:nil];

[lastViewController dismissViewControllerAnimated:NO completion:nil];

}

点击lastViewController的关闭按钮,代码如下 -

[dict setValue:self forKey:@"viewController"];

[[NSNotificationCenter defaultCenter]postNotificationName:@"BackToRoot" object:nil userInfo:dict];

有人有解决方案吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

您是否尝试过lastViewController.navigationController.popToRootViewController(animated: true )