質問編集履歴
2
コードを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,13 +42,17 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
+
追伸、サンプルコードかなりアバウトに書いてて、間違ってました。修正しました。
|
46
|
+
|
47
|
+
|
48
|
+
|
45
49
|
```Swift
|
46
50
|
|
47
51
|
struct AddressBook {
|
48
52
|
|
49
53
|
let user: String
|
50
54
|
|
51
|
-
let companyInfo: CompanyInfo
|
55
|
+
let companyInfo: CompanyInfo?
|
52
56
|
|
53
57
|
}
|
54
58
|
|
@@ -72,19 +76,31 @@
|
|
72
76
|
|
73
77
|
import UIKit
|
74
78
|
|
75
|
-
class ViewController
|
79
|
+
class ViewAViewController: UIViewController {
|
76
80
|
|
77
81
|
private let viewAPresenter = viewAPresenter()
|
78
82
|
|
83
|
+
var addressBook: AddressBook = AddressBook(user: "田中太郎", companyInfo: nil)
|
84
|
+
|
85
|
+
}
|
86
|
+
|
79
87
|
override func viewDidLoad() {
|
80
88
|
|
81
89
|
self.viewAPresenter.viewA = self
|
82
90
|
|
83
91
|
}
|
84
92
|
|
93
|
+
|
94
|
+
|
95
|
+
override func viewWillAppear(_ animated: Bool) {
|
96
|
+
|
97
|
+
self.viewAPresenter.viewWillAppear(data: addressBook)
|
98
|
+
|
85
|
-
}
|
99
|
+
}
|
100
|
+
|
86
|
-
|
101
|
+
}
|
102
|
+
|
87
|
-
extention ViewContorller
|
103
|
+
extention ViewAViewContorller: ViewDelegate {
|
88
104
|
|
89
105
|
}
|
90
106
|
|
@@ -98,7 +114,17 @@
|
|
98
114
|
|
99
115
|
weak var ViewA: AddHospitalDelegate?
|
100
116
|
|
101
|
-
var addressBook: AddressBook
|
117
|
+
var addressBook: AddressBook!
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
func viewWillAppear(data: AddressBook) {
|
122
|
+
|
123
|
+
self.addressBook = data
|
124
|
+
|
125
|
+
print(self.addressBook)
|
126
|
+
|
127
|
+
}
|
102
128
|
|
103
129
|
}
|
104
130
|
|
@@ -106,7 +132,7 @@
|
|
106
132
|
|
107
133
|
// ViewADelegate
|
108
134
|
|
109
|
-
protocol ViewA
|
135
|
+
protocol ViewADelegate : class {
|
110
136
|
|
111
137
|
}
|
112
138
|
|
@@ -118,7 +144,7 @@
|
|
118
144
|
|
119
145
|
import UIKit
|
120
146
|
|
121
|
-
class ViewController
|
147
|
+
class ViewBViewController: UIViewController {
|
122
148
|
|
123
149
|
private let viewBPresenter = viewBPresenter()
|
124
150
|
|
@@ -140,7 +166,7 @@
|
|
140
166
|
|
141
167
|
|
142
168
|
|
143
|
-
extention ViewContorller
|
169
|
+
extention ViewBViewContorller: ViewDelegate {
|
144
170
|
|
145
171
|
}
|
146
172
|
|
@@ -154,7 +180,7 @@
|
|
154
180
|
|
155
181
|
weak var ViewB: AddHospitalDelegate?
|
156
182
|
|
157
|
-
var companyInfo:CompanyInfo = CompanyInfo()
|
183
|
+
var companyInfo:CompanyInfo = CompanyInfo(name: "A会社", address: "B県C市", tel: "0XX-XXX-XXXX")
|
158
184
|
|
159
185
|
|
160
186
|
|
@@ -168,9 +194,9 @@
|
|
168
194
|
|
169
195
|
// 下記もダメでした
|
170
196
|
|
171
|
-
let viewA
|
197
|
+
let viewA = self.storyboard?.instantiateViewController(withIdentifier: "viewA") as! ViewAViewController
|
172
|
-
|
198
|
+
|
173
|
-
viewA
|
199
|
+
viewA.addressbook.companyInfo = companyInfo
|
174
200
|
|
175
201
|
}
|
176
202
|
|
@@ -180,7 +206,7 @@
|
|
180
206
|
|
181
207
|
// ViewBDelegate
|
182
208
|
|
183
|
-
protocol ViewB
|
209
|
+
protocol ViewBDelegate : class {
|
184
210
|
|
185
211
|
}
|
186
212
|
|
1
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,7 +98,7 @@
|
|
98
98
|
|
99
99
|
weak var ViewA: AddHospitalDelegate?
|
100
100
|
|
101
|
-
var AddressBook
|
101
|
+
var addressBook: AddressBook = AddressBook()
|
102
102
|
|
103
103
|
}
|
104
104
|
|
@@ -128,7 +128,17 @@
|
|
128
128
|
|
129
129
|
}
|
130
130
|
|
131
|
+
|
132
|
+
|
133
|
+
override func viewWillDisappear(_ animated: Bool) {
|
134
|
+
|
135
|
+
self.viewBPresenter.viewWillDisappear()
|
136
|
+
|
137
|
+
}
|
138
|
+
|
131
139
|
}
|
140
|
+
|
141
|
+
|
132
142
|
|
133
143
|
extention ViewContorllerB: ViewDelegate {
|
134
144
|
|
@@ -144,7 +154,25 @@
|
|
144
154
|
|
145
155
|
weak var ViewB: AddHospitalDelegate?
|
146
156
|
|
147
|
-
var
|
157
|
+
var companyInfo:CompanyInfo = CompanyInfo()
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
func viewWillDisappear() {
|
162
|
+
|
163
|
+
// 下記ダメでした
|
164
|
+
|
165
|
+
let viewAPresenter = ViewAPresenter()
|
166
|
+
|
167
|
+
viewAPresenter.Addressbook.companyInfo = companyInfo
|
168
|
+
|
169
|
+
// 下記もダメでした
|
170
|
+
|
171
|
+
let viewAPresenter = self.storyboard?.instantiateViewController(withIdentifier: "viewA") as! ViewAViewController
|
172
|
+
|
173
|
+
viewAPresenter.addressbook.companyInfo = companyInfo
|
174
|
+
|
175
|
+
}
|
148
176
|
|
149
177
|
}
|
150
178
|
|