这是我的代码: 我让用户能够从手机中选择图像,然后想要跳回到传递此图像文件的上一个视图控制器..
@IBAction func unwindToThisViewController(segue: UIStoryboardSegue) {
if (segue.identifier == "unwindToThis") {
}
}
答案 0 :(得分:0)
如果原始视图控制器仍在内存中加载,则可以通过NSNotificationCenter使用NSNotification。
在需要数据的视图控制器中,在viewDidLoad:
中NSNotificationCenter.defaultCenter().addObserver(self, selector: "imageReceived:", name: "imageReceived", object: self.videoDeviceInput?.device)
然后将deinit方法添加到同一个控制器,这将在视图控制器不再加载时删除观察者。
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self, name: "imageReceived", object: nil)
}
仍然在同一个类中创建一个处理通知的方法:
func imageReceived(notification: NSNotification) {
if let image = notification.object as? UIImage {
// Do your image stuff here.
}
}
在您创建或获取需要传回的数据的视图控制器中,您可以使用如下数据触发通知:
NSNotificationCenter.defaultCenter().postNotificationName("imageReceived", object: yourUIImage)