質問するログイン新規登録

回答編集履歴

3

修正

2016/08/25 14:54

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -44,4 +44,42 @@
44
44
 
45
45
  サンプル
46
46
  ---
47
- [teratail_45593 サンプル](https://github.com/KentarouKanno/teratail_45593)
47
+ [teratail_45593 サンプル](https://github.com/KentarouKanno/teratail_45593)
48
+
49
+ 回答追記
50
+ ---
51
+
52
+ ```swift
53
+ import UIKit
54
+
55
+ // VC1
56
+ class ViewController1: UIViewController {
57
+
58
+ func modalBackMothod() {
59
+ print("Modal Back!")
60
+ }
61
+
62
+ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
63
+
64
+ // 遷移先がViewController2という設定
65
+ if let vi = segue.destinationViewController as? ViewController2 {
66
+ vi.backClosure = {
67
+ self.modalBackMothod()
68
+ }
69
+ }
70
+ }
71
+ }
72
+
73
+ // VC2
74
+ class ViewController2: UIViewController {
75
+ // Closure
76
+ var backClosure: (() -> Void)!
77
+
78
+ @IBAction func modalCloseButton(sender: UIButton) {
79
+ // 閉じるボタン押下処理
80
+ dismissViewControllerAnimated(true) {
81
+ self.backClosure()
82
+ }
83
+ }
84
+ }
85
+ ```

2

修正

2016/08/25 14:53

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -40,4 +40,8 @@
40
40
  dismissViewControllerAnimated(true, completion: nil)
41
41
  }
42
42
  }
43
- ```
43
+ ```
44
+
45
+ サンプル
46
+ ---
47
+ [teratail_45593 サンプル](https://github.com/KentarouKanno/teratail_45593)

1

修正

2016/08/25 13:55

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -5,8 +5,9 @@
5
5
 
6
6
  import UIKit
7
7
 
8
+ // VC1
8
9
  class ViewController1: UIViewController {
9
- // 遷移を管理するフラグ
10
+ // 遷移状態を管理するフラグ
10
11
  var isModalBackflg = false
11
12
 
12
13
  override func viewDidAppear(animated: Bool) {
@@ -18,6 +19,7 @@
18
19
  }
19
20
  }
20
21
 
22
+ // モーダルが閉じた後に実行されるメソッド
21
23
  func modalBackMothod() {
22
24
  print("Modal Back!")
23
25
  }
@@ -31,9 +33,9 @@
31
33
  }
32
34
  }
33
35
 
34
-
36
+ // VC2
35
37
  class ViewController2: UIViewController {
36
-
38
+ // 閉じるボタン押下処理
37
39
  @IBAction func modalCloseButton(sender: UIButton) {
38
40
  dismissViewControllerAnimated(true, completion: nil)
39
41
  }