質問編集履歴

8

訂正

2019/12/27 18:15

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- ![Storyboard](efc7a679cfacacc68510f2f4a7a7f407.png)
11
+ ![イメージ説明](d0752b871a36b288ded85a5006022a60.png)
12
12
 
13
13
 
14
14
 
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
 
33
- var upperPageViewController: UpperPageViewController!
33
+ var upperPageViewController: UIPageViewController!
34
-
34
+
35
- var lowerPageViewController: LowerPageViewController!
35
+ var lowerPageViewController: UIPageViewController!
36
36
 
37
37
 
38
38
 
@@ -80,11 +80,11 @@
80
80
 
81
81
  case "EmbedUpperPVC":
82
82
 
83
- upperPageViewController = (segue.destination as! UpperPageViewController)
83
+ upperPageViewController = (segue.destination as! UIPageViewController)
84
84
 
85
85
  case "EmbedLowerPVC":
86
86
 
87
- lowerPageViewController = (segue.destination as! LowerPageViewController)
87
+ lowerPageViewController = (segue.destination as! UIPageViewController)
88
88
 
89
89
  default: fatalError("prepare")
90
90
 
@@ -370,16 +370,4 @@
370
370
 
371
371
 
372
372
 
373
-
374
-
375
- class UpperPageViewController: UIPageViewController {}
376
-
377
-
378
-
379
- class LowerPageViewController: UIPageViewController {}
380
-
381
-
382
-
383
-
384
-
385
373
  ```

7

訂正

2019/12/27 18:15

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -52,21 +52,15 @@
52
52
 
53
53
  super.viewDidLoad()
54
54
 
55
-
56
-
57
55
  // pageViewControllerの設定 -> prepareへ
58
56
 
59
-
60
-
61
57
  // pageControlの設定
62
58
 
63
59
  setUpperPageViewController()
64
60
 
65
61
  setLowerPageViewController()
66
62
 
67
-
68
-
69
-
63
+
70
64
 
71
65
  upperPageViewController?.delegate = self
72
66
 
@@ -126,7 +120,7 @@
126
120
 
127
121
  if completed {
128
122
 
129
- switch pageViewController {
123
+ switch pageViewController {
130
124
 
131
125
  case upperPageViewController:
132
126
 
@@ -144,7 +138,7 @@
144
138
 
145
139
  self.lowerPageViewIndex = index
146
140
 
147
- default: fatalError("pageViewController/didFinishAnimating/fatalError")
141
+ default: fatalError("pageViewController/didFinishAnimating/fatalError")
148
142
 
149
143
  }
150
144
 
@@ -184,26 +178,68 @@
184
178
 
185
179
  str = upperPageViewArray[index]
186
180
 
187
-
188
-
189
181
  case lowerPageViewController:
190
182
 
183
+ index = lowerPageViewIndex
184
+
185
+ if index == 0 { return nil }
186
+
187
+ index -= 1
188
+
189
+ str = lowerPageViewArray[index]
190
+
191
+ default: fatalError("viewControllerBefore/fatalError")
192
+
193
+ }
194
+
195
+ guard let vc = createContentsVC(index: index, str: str) else { return nil }
196
+
197
+
198
+
199
+ return vc
200
+
201
+ }
202
+
203
+
204
+
205
+ func pageViewController(_ pageViewController: UIPageViewController,
206
+
207
+ viewControllerAfter viewController: UIViewController) -> UIViewController?
208
+
209
+ {
210
+
211
+ var index: Int
212
+
213
+ let str: String
214
+
215
+
216
+
217
+ switch pageViewController {
218
+
219
+ case upperPageViewController:
220
+
191
221
  index = upperPageViewIndex
192
222
 
193
- if index == 0 { return nil }
223
+ if index >= upperPageViewArray.count - 1 { return nil }
194
-
224
+
195
- index -= 1
225
+ index += 1
196
226
 
197
227
  str = upperPageViewArray[index]
198
228
 
199
-
229
+ case lowerPageViewController:
230
+
231
+ index = lowerPageViewIndex
232
+
233
+ if index >= lowerPageViewArray.count - 1 { return nil }
234
+
235
+ index += 1
236
+
237
+ str = lowerPageViewArray[index]
200
238
 
201
239
  default: fatalError("viewControllerBefore/fatalError")
202
240
 
203
241
  }
204
242
 
205
-
206
-
207
243
  guard let vc = createContentsVC(index: index, str: str) else { return nil }
208
244
 
209
245
 
@@ -214,51 +250,65 @@
214
250
 
215
251
 
216
252
 
217
- func pageViewController(_ pageViewController: UIPageViewController,
218
-
219
- viewControllerAfter viewController: UIViewController) -> UIViewController?
220
-
221
- {
222
-
223
- var index: Int
224
-
225
- let str: String
226
-
227
-
228
-
229
- switch pageViewController {
230
-
231
- case upperPageViewController:
232
-
233
- index = upperPageViewIndex
234
-
235
- if index >= upperPageViewArray.count - 1 { return nil }
236
-
237
- index += 1
238
-
239
- str = upperPageViewArray[index]
240
-
241
-
242
-
243
- case lowerPageViewController:
244
-
245
- index = upperPageViewIndex
246
-
247
- if index >= lowerPageViewArray.count - 1 { return nil }
248
-
249
- index += 1
250
-
251
- str = upperPageViewArray[index]
252
-
253
-
254
-
255
- default: fatalError("viewControllerBefore/fatalError")
256
-
257
- }
258
-
259
-
260
-
261
- guard let vc = createContentsVC(index: index, str: str) else { return nil }
253
+ }
254
+
255
+
256
+
257
+ // setPageViewController
258
+
259
+ extension ViewController {
260
+
261
+
262
+
263
+ func setUpperPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
264
+
265
+
266
+
267
+ let index = upperPageViewIndex
268
+
269
+ let str = upperPageViewArray[index]
270
+
271
+
272
+
273
+ guard let vc = createContentsVC(index: index, str: str) else { return }
274
+
275
+
276
+
277
+ self.upperPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
278
+
279
+ }
280
+
281
+
282
+
283
+ func setLowerPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
284
+
285
+
286
+
287
+ let index = lowerPageViewIndex
288
+
289
+ let str = lowerPageViewArray[index]
290
+
291
+
292
+
293
+ guard let vc = createContentsVC(index: index, str: str) else { return }
294
+
295
+
296
+
297
+ self.lowerPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
298
+
299
+ }
300
+
301
+
302
+
303
+ func createContentsVC(index: Int, str: String) -> UIViewController? {
304
+
305
+
306
+
307
+ let sb = UIStoryboard(name: "Main", bundle: nil)
308
+
309
+ let vc = sb.instantiateViewController(withIdentifier: "ContentsVC") as! ContentsVC
310
+
311
+ vc.dataSource = ContentsVCDataStore.init(index: index, str: str)
262
312
 
263
313
 
264
314
 
@@ -272,78 +322,6 @@
272
322
 
273
323
 
274
324
 
275
- // setPageViewController
276
-
277
- extension ViewController {
278
-
279
-
280
-
281
- func setUpperPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
282
-
283
-
284
-
285
- let index = upperPageViewIndex
286
-
287
- let str = upperPageViewArray[index]
288
-
289
-
290
-
291
- guard let vc = createContentsVC(index: index, str: str) else { return }
292
-
293
-
294
-
295
- self.upperPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
296
-
297
- }
298
-
299
-
300
-
301
- func setLowerPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
302
-
303
-
304
-
305
- let index = lowerPageViewIndex
306
-
307
- let str = lowerPageViewArray[index]
308
-
309
-
310
-
311
- guard let vc = createContentsVC(index: index, str: str) else { return }
312
-
313
-
314
-
315
- print("setLowerPageVC:",vc)
316
-
317
-
318
-
319
- self.lowerPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
320
-
321
- }
322
-
323
-
324
-
325
- func createContentsVC(index: Int, str: String) -> UIViewController? {
326
-
327
-
328
-
329
- let sb = UIStoryboard(name: "Main", bundle: nil)
330
-
331
- let vc = sb.instantiateViewController(withIdentifier: "ContentsVC") as! ContentsVC
332
-
333
- vc.dataSource = ContentsVCDataStore.init(index: index, str: str)
334
-
335
-
336
-
337
- return vc
338
-
339
- }
340
-
341
-
342
-
343
- }
344
-
345
-
346
-
347
325
 
348
326
 
349
327
  class ContentsVC: UIViewController {
@@ -402,4 +380,6 @@
402
380
 
403
381
 
404
382
 
383
+
384
+
405
385
  ```

6

訂正

2019/12/27 17:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -30,9 +30,9 @@
30
30
 
31
31
 
32
32
 
33
- var upperPageViewController: UpperPageViewController?
33
+ var upperPageViewController: UpperPageViewController!
34
-
34
+
35
- var lowerPageViewController: LowerPageViewController?
35
+ var lowerPageViewController: LowerPageViewController!
36
36
 
37
37
 
38
38
 
@@ -54,18 +54,16 @@
54
54
 
55
55
 
56
56
 
57
- // pageViewControllerの設定
57
+ // pageViewControllerの設定 -> prepareへ
58
-
59
- upperPageViewController = children.first as? UpperPageViewController
58
+
60
-
61
- lowerPageViewController = children.first as? LowerPageViewController
59
+
62
60
 
63
61
  // pageControlの設定
64
62
 
63
+ setUpperPageViewController()
64
+
65
65
  setLowerPageViewController()
66
66
 
67
- setUpperPageViewController()
68
-
69
67
 
70
68
 
71
69
 
@@ -80,6 +78,28 @@
80
78
 
81
79
  }
82
80
 
81
+
82
+
83
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
84
+
85
+ switch segue.identifier {
86
+
87
+ case "EmbedUpperPVC":
88
+
89
+ upperPageViewController = (segue.destination as! UpperPageViewController)
90
+
91
+ case "EmbedLowerPVC":
92
+
93
+ lowerPageViewController = (segue.destination as! LowerPageViewController)
94
+
95
+ default: fatalError("prepare")
96
+
97
+ }
98
+
99
+ }
100
+
101
+
102
+
83
103
  }
84
104
 
85
105
 
@@ -292,6 +312,10 @@
292
312
 
293
313
 
294
314
 
315
+ print("setLowerPageVC:",vc)
316
+
317
+
318
+
295
319
  self.lowerPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
296
320
 
297
321
  }
@@ -376,4 +400,6 @@
376
400
 
377
401
  class LowerPageViewController: UIPageViewController {}
378
402
 
403
+
404
+
379
405
  ```

5

訂正

2019/12/27 17:00

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,11 @@
8
8
 
9
9
 
10
10
 
11
- ![イメージ説明](9b4cc7c3baba6b5fa5154fbefe551d3c.png)
11
+ ![Storyboard](efc7a679cfacacc68510f2f4a7a7f407.png)
12
+
13
+
14
+
15
+ [サンプル](https://github.com/tyobigoro/tPageViewController)
12
16
 
13
17
 
14
18
 
@@ -24,13 +28,23 @@
24
28
 
25
29
  class ViewController: UIViewController {
26
30
 
27
- // 一応PageViewControllerを保持する変数には名前を付けて区別しているが
31
+
28
-
29
- // Storyboard上のどっちのPageViewControllerか指定ができない
32
+
30
-
31
- var upperPageViewController: UIPageViewController?
33
+ var upperPageViewController: UpperPageViewController?
32
-
34
+
33
- var lowerPageViewController: UIPageViewController?
35
+ var lowerPageViewController: LowerPageViewController?
36
+
37
+
38
+
39
+ var upperPageViewArray: [String] = ["A", "B", "C", "D", "E"]
40
+
41
+ var lowerPageViewArray: [String] = ["あ", "か", "さ", "た", "な"]
42
+
43
+
44
+
45
+ var upperPageViewIndex: Int = 0
46
+
47
+ var lowerPageViewIndex: Int = 0
34
48
 
35
49
 
36
50
 
@@ -42,15 +56,17 @@
42
56
 
43
57
  // pageViewControllerの設定
44
58
 
45
- upperPageViewController = children.first as? UIPageViewController
59
+ upperPageViewController = children.first as? UpperPageViewController
46
-
60
+
47
- lowerPageViewController = children.first as? UIPageViewController
61
+ lowerPageViewController = children.first as? LowerPageViewController
48
62
 
49
63
  // pageControlの設定
50
64
 
65
+ setLowerPageViewController()
66
+
51
67
  setUpperPageViewController()
52
68
 
53
- setLowerPageViewController()
69
+
54
70
 
55
71
 
56
72
 
@@ -64,100 +80,300 @@
64
80
 
65
81
  }
66
82
 
67
-
83
+ }
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ extension ViewController: UIPageViewControllerDelegate {
92
+
93
+
94
+
95
+ func pageViewController(_ pageViewController: UIPageViewController,
96
+
97
+ didFinishAnimating finished: Bool,
98
+
99
+ previousViewControllers: [UIViewController],
100
+
101
+ transitionCompleted completed: Bool)
102
+
103
+ {
104
+
105
+
106
+
107
+ if completed {
108
+
109
+ switch pageViewController {
110
+
111
+ case upperPageViewController:
112
+
113
+ guard let vc = upperPageViewController?.viewControllers?.first as? ContentsVC else { return }
114
+
115
+ let index = vc.dataSource.index
116
+
117
+ self.upperPageViewIndex = index
118
+
119
+ case lowerPageViewController:
120
+
121
+ guard let vc = lowerPageViewController?.viewControllers?.first as? ContentsVC else { return }
122
+
123
+ let index = vc.dataSource.index
124
+
125
+ self.lowerPageViewIndex = index
126
+
127
+ default: fatalError("pageViewController/didFinishAnimating/fatalError")
128
+
129
+ }
130
+
131
+ }
132
+
133
+ }
134
+
135
+ }
136
+
137
+
138
+
139
+ extension ViewController: UIPageViewControllerDataSource {
140
+
141
+
142
+
143
+ func pageViewController(_ pageViewController: UIPageViewController,
144
+
145
+ viewControllerBefore viewController: UIViewController) -> UIViewController?
146
+
147
+ {
148
+
149
+ var index: Int
150
+
151
+ let str: String
152
+
153
+
154
+
155
+ switch pageViewController {
156
+
157
+ case upperPageViewController:
158
+
159
+ index = upperPageViewIndex
160
+
161
+ if index == 0 { return nil }
162
+
163
+ index -= 1
164
+
165
+ str = upperPageViewArray[index]
166
+
167
+
168
+
169
+ case lowerPageViewController:
170
+
171
+ index = upperPageViewIndex
172
+
173
+ if index == 0 { return nil }
174
+
175
+ index -= 1
176
+
177
+ str = upperPageViewArray[index]
178
+
179
+
180
+
181
+ default: fatalError("viewControllerBefore/fatalError")
182
+
183
+ }
184
+
185
+
186
+
187
+ guard let vc = createContentsVC(index: index, str: str) else { return nil }
188
+
189
+
190
+
191
+ return vc
192
+
193
+ }
194
+
195
+
196
+
197
+ func pageViewController(_ pageViewController: UIPageViewController,
198
+
199
+ viewControllerAfter viewController: UIViewController) -> UIViewController?
200
+
201
+ {
202
+
203
+ var index: Int
204
+
205
+ let str: String
206
+
207
+
208
+
209
+ switch pageViewController {
210
+
211
+ case upperPageViewController:
212
+
213
+ index = upperPageViewIndex
214
+
215
+ if index >= upperPageViewArray.count - 1 { return nil }
216
+
217
+ index += 1
218
+
219
+ str = upperPageViewArray[index]
220
+
221
+
222
+
223
+ case lowerPageViewController:
224
+
225
+ index = upperPageViewIndex
226
+
227
+ if index >= lowerPageViewArray.count - 1 { return nil }
228
+
229
+ index += 1
230
+
231
+ str = upperPageViewArray[index]
232
+
233
+
234
+
235
+ default: fatalError("viewControllerBefore/fatalError")
236
+
237
+ }
238
+
239
+
240
+
241
+ guard let vc = createContentsVC(index: index, str: str) else { return nil }
242
+
243
+
244
+
245
+ return vc
246
+
247
+ }
248
+
249
+
250
+
251
+ }
252
+
253
+
254
+
255
+ // setPageViewController
256
+
257
+ extension ViewController {
68
258
 
69
259
 
70
260
 
71
261
  func setUpperPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
72
262
 
73
- guard let vc = // ViewControllerを生成
74
-
75
- // presentViewController
76
-
77
- self.upperPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
78
-
79
- }
80
-
81
-
82
-
83
- func setlowerPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
84
-
85
- guard let vc = // ViewControllerを生成
86
-
87
- // presentViewController
88
-
89
- self.lowerPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
90
-
91
- }
92
-
93
-
94
-
95
- }
96
-
97
-
263
+
264
+
265
+ let index = upperPageViewIndex
266
+
267
+ let str = upperPageViewArray[index]
268
+
269
+
270
+
271
+ guard let vc = createContentsVC(index: index, str: str) else { return }
272
+
273
+
274
+
275
+ self.upperPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
276
+
277
+ }
278
+
279
+
280
+
281
+ func setLowerPageViewController(direction: UIPageViewController.NavigationDirection = .forward) {
282
+
283
+
284
+
285
+ let index = lowerPageViewIndex
286
+
287
+ let str = lowerPageViewArray[index]
288
+
289
+
290
+
291
+ guard let vc = createContentsVC(index: index, str: str) else { return }
292
+
293
+
294
+
295
+ self.lowerPageViewController?.setViewControllers([vc], direction: .forward, animated: false, completion: nil)
296
+
297
+ }
298
+
299
+
300
+
301
+ func createContentsVC(index: Int, str: String) -> UIViewController? {
302
+
303
+
304
+
305
+ let sb = UIStoryboard(name: "Main", bundle: nil)
306
+
307
+ let vc = sb.instantiateViewController(withIdentifier: "ContentsVC") as! ContentsVC
308
+
309
+ vc.dataSource = ContentsVCDataStore.init(index: index, str: str)
310
+
311
+
312
+
313
+ return vc
314
+
315
+ }
316
+
317
+
318
+
319
+ }
320
+
321
+
322
+
323
+
324
+
325
+ class ContentsVC: UIViewController {
326
+
327
+
328
+
329
+ var dataSource: ContentsVCDataStore!
330
+
331
+
332
+
333
+ @IBOutlet weak var tLabel: UILabel!
334
+
335
+
336
+
337
+ override func viewDidLoad() {
338
+
339
+ super.viewDidLoad()
340
+
341
+ tLabel.text = dataSource.str
342
+
343
+ }
344
+
345
+ }
346
+
347
+
348
+
349
+ class ContentsVCDataStore {
350
+
351
+
352
+
353
+ var index: Int
354
+
355
+ var str: String
356
+
357
+
358
+
359
+ init(index: Int, str: String) {
360
+
361
+ self.index = index
362
+
363
+ self.str = str
364
+
365
+ }
366
+
367
+ }
368
+
369
+
370
+
371
+
372
+
373
+ class UpperPageViewController: UIPageViewController {}
374
+
375
+
376
+
377
+ class LowerPageViewController: UIPageViewController {}
98
378
 
99
379
  ```
100
-
101
-
102
-
103
-
104
-
105
- ```swift
106
-
107
- // サブクラスを作る
108
-
109
- class UpperPageViewcontroller: UIPageViewController {}
110
-
111
-
112
-
113
- class LowerPageViewController: UIPageViewController {}
114
-
115
-
116
-
117
- class ViewController: UIViewController {
118
-
119
- // 格納する変数を宣言する
120
-
121
- // Storyboard上のどっちのPageViewControllerか指定ができない
122
-
123
- var upperPageViewController: UpperPageViewcontroller?
124
-
125
- var lowerPageViewController: LowerPageViewController?
126
-
127
-
128
-
129
- override func viewDidLoad() {
130
-
131
- super.viewDidLoad()
132
-
133
-
134
-
135
- // pageViewControllerの設定
136
-
137
- upperPageViewController = children.first as? UpperPageViewcontroller
138
-
139
- lowerPageViewController = children.first as? LowerPageViewController
140
-
141
- // pageControlの設定
142
-
143
- setUpperPageViewController()
144
-
145
- setLowerPageViewController()
146
-
147
-
148
-
149
- upperPageViewController?.delegate = self
150
-
151
- upperPageViewController?.dataSource = self
152
-
153
- lowerPageViewController?.delegate = self
154
-
155
- lowerPageViewController?.dataSource = self
156
-
157
- }
158
-
159
-
160
-
161
- ```
162
-
163
- サブクラスを作って、それぞれの変数に適用して、storyboard上の各PageViewControllerにサブクラスを設定すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、どちらかのPageViewControllerしか描写されない状態です。

4

訂正

2019/12/27 16:16

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -160,4 +160,4 @@
160
160
 
161
161
  ```
162
162
 
163
- サブクラスを作って、それぞれの変数に適用して、storyboard上の各PageViewControllerにサブクラスを設定すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、この方法で今後きんと動くない、ご存知でしたら教えて下さい
163
+ サブクラスを作って、それぞれの変数に適用して、storyboard上の各PageViewControllerにサブクラスを設定すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、のPageViewControllerし描写されない状態

3

訂正

2019/12/27 14:05

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -160,4 +160,4 @@
160
160
 
161
161
  ```
162
162
 
163
- サブクラスを作って、それぞれの変数に適用すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、この方法で今後きちんと動くかわからないので、ご存知でしたら教えて下さい。
163
+ サブクラスを作って、それぞれの変数に適用して、storyboard上の各PageViewControllerにサブクラスを設定すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、この方法で今後きちんと動くかわからないので、ご存知でしたら教えて下さい。

2

訂正

2019/12/27 12:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  一つの`ViewController`上に2つの`PageViewController`を設置したいのですが、
2
2
 
3
- `setPageViewController()`で設置する`PageViewController`を選ぶことができません(適当な方へ設置される)。
3
+ `setPageViewController()`/`setViewControllers(_:direction:animated:completion:)`で設置する`PageViewController`を選ぶことができません(適当な方へ設置される)。
4
4
 
5
5
  どちらか指定する方法をご存知でしたら教えて下さい。
6
6
 

1

訂正

2019/12/27 12:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -97,3 +97,67 @@
97
97
 
98
98
 
99
99
  ```
100
+
101
+
102
+
103
+
104
+
105
+ ```swift
106
+
107
+ // サブクラスを作る
108
+
109
+ class UpperPageViewcontroller: UIPageViewController {}
110
+
111
+
112
+
113
+ class LowerPageViewController: UIPageViewController {}
114
+
115
+
116
+
117
+ class ViewController: UIViewController {
118
+
119
+ // 格納する変数を宣言する
120
+
121
+ // Storyboard上のどっちのPageViewControllerか指定ができない
122
+
123
+ var upperPageViewController: UpperPageViewcontroller?
124
+
125
+ var lowerPageViewController: LowerPageViewController?
126
+
127
+
128
+
129
+ override func viewDidLoad() {
130
+
131
+ super.viewDidLoad()
132
+
133
+
134
+
135
+ // pageViewControllerの設定
136
+
137
+ upperPageViewController = children.first as? UpperPageViewcontroller
138
+
139
+ lowerPageViewController = children.first as? LowerPageViewController
140
+
141
+ // pageControlの設定
142
+
143
+ setUpperPageViewController()
144
+
145
+ setLowerPageViewController()
146
+
147
+
148
+
149
+ upperPageViewController?.delegate = self
150
+
151
+ upperPageViewController?.dataSource = self
152
+
153
+ lowerPageViewController?.delegate = self
154
+
155
+ lowerPageViewController?.dataSource = self
156
+
157
+ }
158
+
159
+
160
+
161
+ ```
162
+
163
+ サブクラスを作って、それぞれの変数に適用すると、setViewControllers(_:direction:animated:completion:)でpageViewControllerの設定先が指定どおりにできたのですが、この方法で今後きちんと動くかわからないので、ご存知でしたら教えて下さい。