回答編集履歴
1
追記
test
CHANGED
@@ -33,3 +33,101 @@
|
|
33
33
|
}
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
----
|
40
|
+
|
41
|
+
追記
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
根本的なことが分かっていないようなので、ちょっと長めの無駄話。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
#### UIViewControllerについて
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
UIViewControllerのリファレンスを読んでみましょう
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
> 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.
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
(超訳)
|
62
|
+
|
63
|
+
UIViewControllerをサブクラス化せずに使うことはめったにない。サブクラス化して便利に使え。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
> A view controller’s main responsibilities include the following:
|
70
|
+
|
71
|
+
>
|
72
|
+
|
73
|
+
> ・Updating the contents of the views, usually in response to changes to the underlying data.
|
74
|
+
|
75
|
+
>
|
76
|
+
|
77
|
+
> ・Responding to user interactions with views.
|
78
|
+
|
79
|
+
>
|
80
|
+
|
81
|
+
> ・Resizing views and managing the layout of the overall interface.
|
82
|
+
|
83
|
+
>
|
84
|
+
|
85
|
+
> ・Coordinating with other objects—including other view controllers—in your app.
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
(超訳)ViewControllerの役割は
|
90
|
+
|
91
|
+
- 持ってるデータを表示する
|
92
|
+
|
93
|
+
- ユーザーアクションへの対応
|
94
|
+
|
95
|
+
- ビューレイアウト管理
|
96
|
+
|
97
|
+
- ほかのオブジェクトとの連携
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
#### 外側から考える
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
ViewControllerの役割をその外から考えると、ViewControllerにデータを与えると**詳細はわからないけどユーザーにそれが表示される**ということです。
|
106
|
+
|
107
|
+
ViewControllerの外からデータがどのように表示されるかを**考えてはいけません**。それはViewControllerの仕事です。
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
#### あなたがやるべきこと
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
ContainerViewがやるべき仕事は、一つの`(title: String, items: [String])`を保持し、それを表示することです。
|
118
|
+
|
119
|
+
そのリストを**持ってはいけません**。
|
120
|
+
|
121
|
+
そしてそれが変更されたときは、新しい内容を表示しなければなりません。
|
122
|
+
|
123
|
+
そのようにプログラムを組みましょう。
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
テーブルのセルが選択されたとき、ContainerViewに表示すべきデータを渡すのがViewControllerの役割です。
|
130
|
+
|
131
|
+
それ以上のことをしてはいけません。
|
132
|
+
|
133
|
+
そのようにプログラムを組みましょう。
|