标签:storyboard mvc ios 开发
有一次在做vc跳转的时候,居然跳转过去全是黑的
用的代码:
self.navigationController?.pushViewController(secondViewController(), animated: true)
看了视频很快解决了问题,得用storyboard id实例化视图
let secondVc = self.storyboard?.instantiateViewControllerWithIdentifier("secondvc") as! secondViewController
问题是解决了,但是这也让我产生了疑惑:到底storyboard做了哪些工作。
对这个问题研究下去我发现了这些东西:
接下来就是我对跳转视图出现黑屏现象的解释与理解:
self.navigationController?.pushViewController(secondViewController(), animated: true)
secondViewController()
,这里边并没有加载view的实现为了验证我这说法,我做了一个具体的验证:
我在secondView中添加了以下代码:
override func viewDidLoad() {
super.viewDidLoad()
let lable:UILabel = UILabel(frame: CGRect(x: 50, y: 200, width: 50, height: 50))
lable.backgroundColor=UIColor.redColor()
lable.text = "lable"
self.view.addSubview(lable)
// Do any additional setup after loading the view.
}
依旧使用代码:
self.navigationController?.pushViewController(secondViewController(), animated: true)
进行跳转
结果显示是这样
结果也证实了我的说法,
原因就是实例化的VC 并没有把自己写的view(以及控件)添加到VC的View上
标签:storyboard mvc ios 开发
原文地址:http://blog.csdn.net/li962429707/article/details/45797835