6

我正在调用我正在调用的应用程序,presentModalViewController一旦完成(调用dismissModalViewControllerAnimated:YES)它应该立即调用popToRootViewControllerAnimated

但问题是dismissModalViewControllerAnimated:YES工作正常,但popToRootViewControllerAnimated在此之后无法正常工作。

代码如下所示:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];
4

4 回答 4

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] ;

呈现模式的对象是视图控制器,而不是导航控制器。

于 2010-10-04T06:21:22.110 回答
2

如果您有一个带有 UIViewController 堆栈的导航控制器:

[self dismissModalViewControllerAnimated:YES];
[(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES];
//UIViewController *vc = [[UIViewController new] autorelease];
//[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES];

假设调用模态视图控制器的视图控制器具有navigationController。

于 2011-08-10T14:31:25.203 回答
0

我想,你没有打电话给

[self.navigationController popToRootViewControllerAnimated:YES];

在目标模态视图控制器中。检查一下。

于 2010-10-04T06:40:26.580 回答
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];

请参阅:如何从 UINavigationController 弹出视图并在一次操作中将其替换为另一个视图?

于 2011-10-19T23:35:01.817 回答