0

在从触发展开转场的模态视图中采取特定操作后,我试图更改 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 = ""
    }
}
}

我究竟做错了什么?

4

1 回答 1

0

我做到了!我最终使用了一个全局布尔变量。我在菜单的初始加载时将其设置为 true,然后在展开 segue 期间将其翻转为 false。

var removeExperiment = false

class DataViewController: UIViewController { 

 @IBAction func removeExperimentSegue(unwindSegue:UIStoryboardSegue) {
    removeExperiment = true
}

if removeExperiment == true {
        doneLabel.text = "You've completed this experiment. You won't see it again unless you hit 'Reset' from the Home menu."
    }

}

希望有帮助!

于 2015-05-25T21:25:16.120 回答