回答編集履歴

3

修正

2016/08/25 14:54

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -91,3 +91,79 @@
91
91
  ---
92
92
 
93
93
  [teratail_45593 サンプル](https://github.com/KentarouKanno/teratail_45593)
94
+
95
+
96
+
97
+ 回答追記
98
+
99
+ ---
100
+
101
+
102
+
103
+ ```swift
104
+
105
+ import UIKit
106
+
107
+
108
+
109
+ // VC1
110
+
111
+ class ViewController1: UIViewController {
112
+
113
+
114
+
115
+ func modalBackMothod() {
116
+
117
+ print("Modal Back!")
118
+
119
+ }
120
+
121
+
122
+
123
+ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
124
+
125
+
126
+
127
+ // 遷移先がViewController2という設定
128
+
129
+ if let vi = segue.destinationViewController as? ViewController2 {
130
+
131
+ vi.backClosure = {
132
+
133
+ self.modalBackMothod()
134
+
135
+ }
136
+
137
+ }
138
+
139
+ }
140
+
141
+ }
142
+
143
+
144
+
145
+ // VC2
146
+
147
+ class ViewController2: UIViewController {
148
+
149
+ // Closure
150
+
151
+ var backClosure: (() -> Void)!
152
+
153
+
154
+
155
+ @IBAction func modalCloseButton(sender: UIButton) {
156
+
157
+ // 閉じるボタン押下処理
158
+
159
+ dismissViewControllerAnimated(true) {
160
+
161
+ self.backClosure()
162
+
163
+ }
164
+
165
+ }
166
+
167
+ }
168
+
169
+ ```

2

修正

2016/08/25 14:53

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -83,3 +83,11 @@
83
83
  }
84
84
 
85
85
  ```
86
+
87
+
88
+
89
+ サンプル
90
+
91
+ ---
92
+
93
+ [teratail_45593 サンプル](https://github.com/KentarouKanno/teratail_45593)

1

修正

2016/08/25 13:55

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -12,9 +12,11 @@
12
12
 
13
13
 
14
14
 
15
+ // VC1
16
+
15
17
  class ViewController1: UIViewController {
16
18
 
17
- // 遷移を管理するフラグ
19
+ // 遷移状態を管理するフラグ
18
20
 
19
21
  var isModalBackflg = false
20
22
 
@@ -37,6 +39,8 @@
37
39
  }
38
40
 
39
41
 
42
+
43
+ // モーダルが閉じた後に実行されるメソッド
40
44
 
41
45
  func modalBackMothod() {
42
46
 
@@ -64,11 +68,11 @@
64
68
 
65
69
 
66
70
 
67
-
71
+ // VC2
68
72
 
69
73
  class ViewController2: UIViewController {
70
74
 
71
-
75
+ // 閉じるボタン押下処理
72
76
 
73
77
  @IBAction func modalCloseButton(sender: UIButton) {
74
78