回答編集履歴
1
追記
answer
CHANGED
@@ -15,4 +15,53 @@
|
|
15
15
|
|
16
16
|
/////
|
17
17
|
}
|
18
|
-
```
|
18
|
+
```
|
19
|
+
|
20
|
+
----
|
21
|
+
追記
|
22
|
+
|
23
|
+
根本的なことが分かっていないようなので、ちょっと長めの無駄話。
|
24
|
+
|
25
|
+
#### UIViewControllerについて
|
26
|
+
|
27
|
+
UIViewControllerのリファレンスを読んでみましょう
|
28
|
+
|
29
|
+
> You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
|
30
|
+
|
31
|
+
(超訳)
|
32
|
+
UIViewControllerをサブクラス化せずに使うことはめったにない。サブクラス化して便利に使え。
|
33
|
+
|
34
|
+
|
35
|
+
> A view controller’s main responsibilities include the following:
|
36
|
+
>
|
37
|
+
> ・Updating the contents of the views, usually in response to changes to the underlying data.
|
38
|
+
>
|
39
|
+
> ・Responding to user interactions with views.
|
40
|
+
>
|
41
|
+
> ・Resizing views and managing the layout of the overall interface.
|
42
|
+
>
|
43
|
+
> ・Coordinating with other objects—including other view controllers—in your app.
|
44
|
+
|
45
|
+
(超訳)ViewControllerの役割は
|
46
|
+
- 持ってるデータを表示する
|
47
|
+
- ユーザーアクションへの対応
|
48
|
+
- ビューレイアウト管理
|
49
|
+
- ほかのオブジェクトとの連携
|
50
|
+
|
51
|
+
#### 外側から考える
|
52
|
+
|
53
|
+
ViewControllerの役割をその外から考えると、ViewControllerにデータを与えると**詳細はわからないけどユーザーにそれが表示される**ということです。
|
54
|
+
ViewControllerの外からデータがどのように表示されるかを**考えてはいけません**。それはViewControllerの仕事です。
|
55
|
+
|
56
|
+
|
57
|
+
#### あなたがやるべきこと
|
58
|
+
|
59
|
+
ContainerViewがやるべき仕事は、一つの`(title: String, items: [String])`を保持し、それを表示することです。
|
60
|
+
そのリストを**持ってはいけません**。
|
61
|
+
そしてそれが変更されたときは、新しい内容を表示しなければなりません。
|
62
|
+
そのようにプログラムを組みましょう。
|
63
|
+
|
64
|
+
|
65
|
+
テーブルのセルが選択されたとき、ContainerViewに表示すべきデータを渡すのがViewControllerの役割です。
|
66
|
+
それ以上のことをしてはいけません。
|
67
|
+
そのようにプログラムを組みましょう。
|