推送不适用于以模态方式呈现的控制器
push is not working on the controller which was presented modally
你好,我在 FirstViewController 上有一个按钮,我将一个 segue 从 firstViewController 拖到 secondViewController 作为 segue Modally。现在在 secondViewController 上我以编程方式生成一个 Button 并继续第三个控制器我正在推动控制器(segue Push)但它不起作用。第三个控制器没有出现。单击自定义按钮时没有任何反应。
这是secondViewController的代码
func nextButtonClicked(sender:UIButton!){
let takeProductPhotoController = self.storyboard!.instantiateViewControllerWithIdentifier("takeProductPhotoController") as! TakeProductPhotoController
takeProductPhotoController.trip = trip
self.navigationController?.pushViewController(takeProductPhotoController, animated: true)
}
注意:我不需要第二个视图控制器上的 NavigationBar,因此在以模态方式呈现它时它没有显示 navigationBar。但我需要第三个导航栏。所以这就是我推动 naviagtioncontroller
的原因
- 每当你想从弹出的控制器中推送时,你必须创建
新的
NavigationController
& 还设置了 ViewController
你
想将模态呈现为 rootViewController
of navigationController
.
- 当我们想要呈现
SecondViewcontroller
模态时,我们正在呈现
rootViewController
设置为 SecondViewController
的导航控制器。所以我们
已经创建了新的导航堆栈。之后我们要
将控制器推送到呈现 SecondViewController
. 时创建的新导航堆栈中
1) 你的代码应该是这样的
在 FirstViewController
let secondViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("aIdentifier") as! SecondViewController
let nav = UINavigationController(rootViewController: SecondViewController )
self.presentViewController(nav, animated:true, completion:nil)
2) 从 secondViewController
你可以推入 ThirdViewController
self.naviagtionController
。
在 SecondViewController 中的 Button Action
中编写以下代码
let thirdViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("cIdentifier") as! ThirdViewController self.navigationController?.pushViewController(thirdViewController , animated: true)}
好的,我在这里详细发布了我在做什么以及我做了什么来解决 Rohit Answer 帮助我的问题。
我的 FirstVC
通过 segue 在 IB 中作为 presentModally
连接到 SecondVC
。然后在 SecondVC 中,当我尝试推送 ThirdVC
let thirdVC = self.storyboard!.instantiateViewControllerWithIdentifier("thirdVC") as! ThirdVC
self.navigationController?.pushViewController(thirdVC, animated: true)
没用。
所以为了解决这个问题,我从 IB 中删除了 FirstVC 和 SecondVC 之间的 segue
并将这段代码写在我的 firstVC
let secondVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("secondVC") as! SecondVC
let nav = UINavigationController(rootViewController: secondViewController )
self.presentViewController(nav, animated:true, completion:nil)
然后在 secondVC
let thirdVC = self.storyboard!.instantiateViewControllerWithIdentifier("thirdVC") as! ThirdVC
self.navigationController?.pushViewController(thirdVC, animated: true)
它有效
你好,我在 FirstViewController 上有一个按钮,我将一个 segue 从 firstViewController 拖到 secondViewController 作为 segue Modally。现在在 secondViewController 上我以编程方式生成一个 Button 并继续第三个控制器我正在推动控制器(segue Push)但它不起作用。第三个控制器没有出现。单击自定义按钮时没有任何反应。
这是secondViewController的代码
func nextButtonClicked(sender:UIButton!){
let takeProductPhotoController = self.storyboard!.instantiateViewControllerWithIdentifier("takeProductPhotoController") as! TakeProductPhotoController
takeProductPhotoController.trip = trip
self.navigationController?.pushViewController(takeProductPhotoController, animated: true)
}
注意:我不需要第二个视图控制器上的 NavigationBar,因此在以模态方式呈现它时它没有显示 navigationBar。但我需要第三个导航栏。所以这就是我推动 naviagtioncontroller
的原因- 每当你想从弹出的控制器中推送时,你必须创建
新的
NavigationController
& 还设置了ViewController
你 想将模态呈现为rootViewController
ofnavigationController
. - 当我们想要呈现
SecondViewcontroller
模态时,我们正在呈现rootViewController
设置为SecondViewController
的导航控制器。所以我们 已经创建了新的导航堆栈。之后我们要 将控制器推送到呈现SecondViewController
. 时创建的新导航堆栈中
1) 你的代码应该是这样的
在 FirstViewController
let secondViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("aIdentifier") as! SecondViewController
let nav = UINavigationController(rootViewController: SecondViewController )
self.presentViewController(nav, animated:true, completion:nil)
2) 从 secondViewController
你可以推入 ThirdViewController
self.naviagtionController
。
在 SecondViewController 中的 Button Action
let thirdViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("cIdentifier") as! ThirdViewController self.navigationController?.pushViewController(thirdViewController , animated: true)}
好的,我在这里详细发布了我在做什么以及我做了什么来解决 Rohit Answer 帮助我的问题。
我的 FirstVC
通过 segue 在 IB 中作为 presentModally
连接到 SecondVC
。然后在 SecondVC 中,当我尝试推送 ThirdVC
let thirdVC = self.storyboard!.instantiateViewControllerWithIdentifier("thirdVC") as! ThirdVC
self.navigationController?.pushViewController(thirdVC, animated: true)
没用。
所以为了解决这个问题,我从 IB 中删除了 FirstVC 和 SecondVC 之间的 segue
并将这段代码写在我的 firstVC
let secondVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("secondVC") as! SecondVC
let nav = UINavigationController(rootViewController: secondViewController )
self.presentViewController(nav, animated:true, completion:nil)
然后在 secondVC
let thirdVC = self.storyboard!.instantiateViewControllerWithIdentifier("thirdVC") as! ThirdVC
self.navigationController?.pushViewController(thirdVC, animated: true)
它有效