2016-09-19 33 views
-2

我有三個視圖控制器,說root,middle,last。我想從lastViewController回到rootViewController如何解除中間viewController並返回到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];

有沒有人有這方面的解決方案? 在此先感謝。

+2

顯示您的導航代碼.. – vaibhav

回答

0

你有沒有試過lastViewController.navigationController.popToRootViewController(animated: true)

+0

OP不使用導航控制器。 –

+0

OP?所以你不想去「回」 – CZ54

+0

我沒有使用導航控制器。想用dismissViewController來做到這一點。 – Tejashree