ios - 使用 popToViewController 返回到黑屏的特定 View Controller 时出现问题

标签 ios objective-c uinavigationcontroller storyboard

我正在使用像这样的基本操作来推送到 View 。

UIStoryboard *storyboard = self.navigationController.storyboard;

MenuViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"menuViewController"];

[self.navigationController pushViewController:viewController animated:YES];

一些我可以简单使用的地方:

[self.navigationController popViewControllerAnimated:YES];

但在一些地方我想弹出一个特定的 View Controller 。我尝试过的是:

UIStoryboard *storyboard = self.navigationController.storyboard;

RecordMenuViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"recordMenuViewController"];

[self.navigationController popToViewController:viewController animated:YES];

但它只是进入黑屏,就像 View 不在堆栈中一样。我在这里缺少什么?

最佳答案

如果您想使用导航堆栈弹出到特定的 View Controller ,请执行以下操作:

NSArray* vcs = self.navigationController.viewControllers;
UIViewController* target = [vcs objectAtIndex:([vcs count] - 1) - numVCsToGoBack];
[self.navigationController popToViewController:target];

关于ios - 使用 popToViewController 返回到黑屏的特定 View Controller 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31259258/

相关文章:

ios - 如何使键盘在 iOS 中以编程方式消失

php - Swift 不解析来自 PHP 服务器的 JSON

ios - UIView 与 UISegmentedControl 重叠

ios - 将多个 UIButton 组合成一个按钮

iOS 7 添加了向右滑动以从堆栈中弹出 View Controller 。是否可以通过向左滑动将其添加回去?

iphone - 带有自定义后退按钮的 UINavigationController 子类

css - 如何在 iOS 上使用 CSS overflow 获取滚动条

ios - [外设maximumWriteValueLengthForType :CBCharacteristicWriteWithResponse] return?]是什么意思

objective-c - 有没有办法检测当前可见的 UIView?

ios - 如何将 View 添加为某些 Controller 的 subview