在UINavigation中推送ViewController与在下一个视图中更改值方面呈现ViewController的含义有什么关系?navigationController!.pushViewController与iOS中的presentViewController Swift
例如,为什么第一个工作但不是第二个?
第一:
var textController: TextViewController
textController = self.storyboard!.instantiateViewControllerWithIdentifier("TextViewController") as! TextViewController
presentViewController(textController, animated: false, completion: nil)
textController.textDetail.text = Categories[indexPath.row]
二:
var textController: TextViewController
textController = self.storyboard!.instantiateViewControllerWithIdentifier("TextViewController") as! TextViewController
self.navigationController!.pushViewController(textController,animated:true)
textController.textDetail.text = Categories[indexPath.row]
我不能获取标签的价值在导航堆栈推时改变。
1.你如何实例化'textController'? 2.你如何实例化'textDetail'?假设1. textController是一个UIViewController,并且2.在这两种情况下,您刚刚在此代码之前实例化了'textController',并且3.'textDetail'是一个IBOutlet,它不会在'textController'的初始化过程中实例化,并且在任何情况下都无法设置其文本值,因此您需要稍后在View Controller生命周期中等待。 –
我添加了实例化它的代码。第一个改变标签的值,但第二个给我一个解包错误 –
解包错误发生在哪里?它发生在线上:'self.navigationController!.pushViewController(textController,animated:true)'?如果没有:这两个代码块是否在viewController代码中的相同位置发生?你如何实例化'textDetail'? –