ios - Pass data from one view controller to the other using unwind segue with identifier -
here code: making user able select image phone , want jump previous view controller passing image file too..
@ibaction func unwindtothisviewcontroller(segue: uistoryboardsegue) { if (segue.identifier == "unwindtothis") { } }
if original view controller still loaded in memory can use nsnotification via nsnotificationcenter.
in view controller needs data, in viewdidload:
nsnotificationcenter.defaultcenter().addobserver(self, selector: "imagereceived:", name: "imagereceived", object: self.videodeviceinput?.device)
then add deinit method same controller, remove observer when view controller no longer loaded.
deinit { nsnotificationcenter.defaultcenter().removeobserver(self, name: "imagereceived", object: nil) }
still in same class create method handle notification:
func imagereceived(notification: nsnotification) { if let image = notification.object as? uiimage { // image stuff here. } }
in view controller create or data need pass can trigger notification data so:
nsnotificationcenter.defaultcenter().postnotificationname("imagereceived", object: youruiimage)
Comments
Post a Comment