1

我环顾四周,但没有找到令人满意的答案。我的问题是,每当我打电话时 popToRootViewControllerAnimated:(BOOL),它什么也没做。当我 NSLog 它时,它会记录(null). 让我在这里稍微备份一下。我有一个表视图控制器,它有一个列表,在顶部的导航栏有一个添加选项,它带我到一个新的视图控制器,它带有一个 segue “Present as PopOver”,它摆脱了主体或主要导航栏。所以我手动制作了一个并添加了 2 个栏按钮项“取消”和“添加”。当点击“取消”时,它应该将用户带回表格视图控制器并放弃更改,当点击“添加”按钮时,它还应该将用户带回之前的表格视图控制器并进行更改。但它什么也没做。

这是我的代码。

- (IBAction)cancelButton:(UIBarButtonItem *)sender {
UINavigationController * navigationController = self.navigationController;
NSLog(@"%@", navigationController);
NSLog(@"cancel tapped though");
ListingTableViewController *rootController = [[ListingTableViewController alloc] init];
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:rootController animated:YES];
}

至于segue,这个视图控制器没有连接到任何东西,或者我应该连接它吗?这确实是一个菜鸟问题。这是我的 xcode 屏幕截图。

检查此链接以获取故事板的屏幕截图 http://i.stack.imgur.com/lqnCF.png

4

2 回答 2

1

呈现视图时,您不是在导航控制器中推送它,而是呈现它。要关闭它,请尝试使用[self.presentingViewController dismissViewControllerAnimated:NO completion:nil].

于 2014-06-29T16:09:18.403 回答
1

你必须打电话

- (IBAction)cancelButton:(UIBarButtonItem *)sender {

    NSLog(@"cancel tapped though");
    [self dismissViewControllerAnimated:YES completion:nil]; 
}

而不是popToRootViewControllerAnimated因为你的 VC 出现了而不是被推!

于 2014-06-29T16:09:29.353 回答