我有两个视图控制器一个是主ViewController在底部我把容器视图和该容器连接到另一个NewViewController,我想在主ViewController中显示。 我在ViewController中 JSON数据设置为NewViewController的标签它给我的错误致命错误:意外发现零而展开的可选值错误,而分配字符串uilabel swift
ViewController.swift
let nvc = NewViewController()
func someFunction {
let data = JSON as! NSDictionary
let result = data["result"] as! NSArray
let mytitle = result.valueForKey("name") as! NSArray
let count = mytitle.count - 1
for index in 0...count {
let nameOfPlace = mytitle[index] as! String
print(nameOfPlace) //prints all the names of places
self.nvc.nameLabel.text = nameOfPlace //Thread 1:EXC_BAD_INSTRUCTION
}
NewViewController.swift
@IBOutlet weak var nameLabel: UILabel!
可能重复[致命错误:意外地发现零,而解包可选值 - 为什么?](http://stackoverflow.com/questions/26348996/fatal-error-unexpectedly-found-nil-while-unwrapping-an -optional-value-why)(specific)&[什么是“致命错误:意外地发现零,而解包可选值”是什么意思?](http://stackoverflow.com/questions/32170456/what-does-fatal-error -un-un-pre-one-optional-value)(canonical) – Hamish
另外你的viewController应该创建你的故事板的参考 –