我正在使用我调用presentModalViewController
的应用程序,一旦完成(调用dismissModalViewControllerAnimated:YES
),它应立即调用popToRootViewControllerAnimated
。
但问题是dismissModalViewControllerAnimated:YES
工作正常,但popToRootViewControllerAnimated
无效。
代码如下所示:
[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];
答案 0 :(得分:6)
尝试这样的事情:
[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3];
-(void)patchSelector{
[self.navigationController popToRootViewControllerAnimated:YES];
}
它不是那么整洁但它应该有用。
<强>更新强> 你应该使用
[self dismissModalViewControllerAnimated:YES];
代替
[self.navigationController dismissModalViewControllerAnimated:YES] ;
呈现模态的对象是视图控制器,而不是导航控制器。
答案 1 :(得分:2)
如果你的导航控制器有一堆UIViewControllers:
[self dismissModalViewControllerAnimated:YES];
[(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES];
//UIViewController *vc = [[UIViewController new] autorelease];
//[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES];
假设,视图控制器中调用了模态视图控制器的导航控制器。
答案 2 :(得分:0)
我想,你没有打电话给
[self.navigationController popToRootViewControllerAnimated:YES];
在目标模态viewcontroller中。检查一下。
答案 3 :(得分:0)
我遇到了类似的事情。你需要先复制你的self.navigationcontroller并保留自己,所以当你调用第二个pop时,仍然有对NC的引用,你仍然存在。
// locally store the navigation controller since
// self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;
// retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];
// Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];
请参阅:How can I pop a view from a UINavigationController and replace it with another in one operation?