Last active
October 4, 2016 05:11
-
-
Save kenichi-odo/ca1036ebb4116d3d09e8dc130a3add8e to your computer and use it in GitHub Desktop.
Storyboardで遷移先画面で処理を終えて元の画面に戻る際に値を受け取る ref: http://qiita.com/kenichi_odo/items/062ae2dbc9f7120257ed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditViewController: UIViewController { | |
var resultHandler: ((String) -> Void)? | |
// 何らかの処理をするメソッド | |
func hogeMethod() { | |
let data = "テスト" | |
// handlerに関数がセットされているか確認 | |
if let handler = self.resultHandler { | |
handler(data) | |
} | |
// ListViewControllerに戻る | |
self.dismiss(animated: true) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListViewController: UIViewController { | |
// Storyboardで遷移時に呼ばれる | |
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) { | |
// 遷移先のコントローラを取得 | |
let controller = segue.destinationViewController as! EditViewController | |
// 遷移先で処理を終えた後の処理をここで書く | |
controller.resultHandler = { data_ in | |
print(data_) // テスト | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment