ios - 在 presentViewController 不起作用后调用 pushViewController

标签 ios iphone uiviewcontroller uinavigationcontroller presentviewcontroller

我正在这样展示我的 View Controller -

[self.navigationController presentViewController:self.thingContainerViewController animated:YES completion:nil]; //self.navigationController not nil here

这显示了一个 UITableView。我想从这里在导航堆栈上推送一个 VC。但是此时 self.navigationController 为 nil。知道如何进行这项工作吗?

[self.navigationController pushViewController:otherContainer animated:YES]; //self.navigationController is nil at this point

最佳答案

您需要将要呈现的 View Controller 包装在导航 Controller 中,以便能够使用 push 和 pop 方法。

第一步:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.thingContainerViewController];

然后:

[self.navigationController presentViewController:navigationController animated:YES completion:nil];

如果你这样做,你的代码就会工作。

关于ios - 在 presentViewController 不起作用后调用 pushViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31599482/

相关文章:

ios - 在 Swift 中为 UIPickerView 委托(delegate)方法

iPhone SDK : Store Kit: Can I host the downloads on my own server?

ios - 当应用程序在 IOS 中发生崩溃时呈现 UIViewController

ios - 应用程序在 iPhone 6s 的 'peek and pop' 实现中卡住

iphone - loadView 与 init 方法

ios - 如何通过 ios UIViewControllers 注入(inject)依赖项

ios - Swift - 当应用程序进入后台状态时,从 AppDelegate 更新 RootViewController 中的值

ios - AdMob 测试广告不起作用 - iOS

ios - 如何使用 GPUImageHarrisCornerDetectionFilter 获取角点

ios - Xcode 要求我将属性重新声明为实例变量