您可以使用NSNotificationCenter
为了那个原因。
首先在你的viewDidLoad
方法将此代码添加到您的firstViewController
class:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "refreshlbl:", name: "refresh", object: nil)
这将addObserver
当您的应用程序加载时。
并在同一个中添加这个辅助方法viewController
.
func refreshlbl(notification: NSNotification) {
lbl.text = "Updated by second View" //Update your label here.
}
之后在你的secondViewController
当您关闭视图时添加此代码:
@IBAction func back(sender: AnyObject) {
NSNotificationCenter.defaultCenter().postNotificationName("refresh", object: nil, userInfo: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}
现在,当您按下后退按钮时secondView
then refreshlbl
方法将调用自firstView
.