在从触发展开转场的模态视图中采取特定操作后,我试图更改 viewController 的标签。
一旦 unwind segue 发生,当前视图的标签(模态覆盖的那个)应该被改变。
我目前这样做的尝试导致“在展开可选值时意外发现 nil”错误。这是代码:
class DataViewController: UIViewController {
var experiment: NSDictionary?
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var bodyLabel: UILabel!
@IBOutlet weak var tlRightLine: UIImageView!
@IBOutlet weak var tlLeftLine: UIImageView!
@IBOutlet weak var brRightLine: UIImageView!
@IBOutlet weak var brLeftLine: UIImageView!
@IBOutlet weak var bodyTest: UITextView!
@IBAction func removeExperimentSegue(unwindSegue:UIStoryboardSegue) {
removeExperiment = true
titleLabel.text = "Done"
bodyLabel.text = "Done"
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if let dict: NSDictionary = experiment {
if let title = dict.objectForKey("title") as? String {
self.titleLabel!.text = title
}
if let body = dict.objectForKey("body") as? String {
self.bodyTest!.text = body
}
} else {
self.titleLabel!.text = ""
self.bodyLabel!.text = ""
}
}
}
我究竟做错了什么?