【问题标题】:How can I push the next view controller on a navigation controller programmatically?如何以编程方式在导航控制器上推送下一个视图控制器?
【发布时间】:2015-06-20 00:14:24
【问题描述】:

如何以编程方式在导航控制器上推送下一个视图控制器(无需按钮)?

我知道如何实例化和呈现一个新的控制器如下

 var next = self.storyboard?.instantiateViewControllerWithIdentifier("PlaceInfo") as! PlaceInfoController         
 self.presentViewController(next, animated: false, completion: nil)

但我想推送到导航控制器上的下一个视图控制器。 我尝试了以下 self.navigationController?.pushViewController() 但没有成功

 var next = self.storyboard?.instantiateViewControllerWithIdentifier("PlaceInfo") as! PlaceInfoController
 self.navigationController?.pushViewController(next, animated: true)

【问题讨论】:

  • 你检查过self.navigationController是不是nil吗?
  • 它是零。知道为什么吗?提前谢谢你@Leo
  • 表示这个viewController不在导航栈中,先把它放到导航栈中,再push另一个

标签: ios swift


【解决方案1】:

【讨论】:

  • 是的,应用程序崩溃了。错误:由于未捕获的异常“NSGenericException”而终止应用程序,原因:“找不到用于 segue 'PushPlaceView' 的导航控制器。只有当源控制器由 UINavigationController 的实例管理时,才能使用推送 segue。 @rodrigochousal
  • 由于@Leo 所说,应用程序崩溃了,视图控制器需要在导航堆栈中才能工作。
猜你喜欢
  • 2021-02-03
  • 1970-01-01
  • 2014-01-11
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多