1.使用delgates
はプロトコルを作成し、プロパティを作成し、あなたのfirstviewcontroller
protocol My {
func returnFilteredImage(image: UIImage)
}
class FirstViewController: UIViewcontroller, My {
...
func returnFilteredImage(image: UIImage) {
}
}
にし、あなたのthirdViewControllerに実装し、これにFirstViewControllerデリゲートを割り当てます。ローカル通知あなたはローカル通知
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//add observer
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.didgetImage(_:)), name: "receiveImageNotification", object: nil)
}
func didgetImage(notification: NSNotification) {
if let image = notification.userInfo?["image"] as? UIImage {
// do something with your image
}
}
}
と3番目のビューコントローラから
を使用してこれを行うことができます
check here
、最初の通知を使用して
class ThirdViewController: UIViewController {
var delegate: My?
...
override func viewDidLoad() {
super.viewDidLoad()
for vc in self.navigationController!.viewControllers{
if vc is FirstViewController {
let vc1 = vc as! FirstViewController
self.delegate = vc1
self.delegate?.returnFilteredImage(imageView.image!)
self.navigationController?.popToViewController(vc, animated: true)
}
}
}
}
2.
let imageDataDict:[String: UIImage] = ["image": image]
NSNotificationCenter.defaultCenter().postNotificationName("receiveImageNotification", object: self, userInfo: imageDataDict)
これは役に立ちます:)
キー値観測を使用することができます。http://nshipster.com/key-value-observing/ – henrikstroem
NSNotificationCenterオブザーバで試しましたか?値を渡すことにのみ関連する場合は、これは便利かもしれません –
@AnkitaShah通知は簡単な方法ですが、委任を試してみたい – ankit