質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,197 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
お手数だとは思いますが、どのように実装すればよいか教えていただきたいです。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
追記:遷移先のクラスです。講義開始時間のセルからdatepickerで値を入力させたいのと、元のクラスに戻る際(具体的にはviewWillDisappear)に各情報を保存させたいです。
|
22
|
+
|
23
|
+
```swift
|
24
|
+
|
25
|
+
import UIKit
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
class ViewController2: UITableViewController{
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
// 講義名
|
34
|
+
|
35
|
+
private let titleCell = UITableViewCell()
|
36
|
+
|
37
|
+
private let titleField = UITextField()
|
38
|
+
|
39
|
+
// 講義内容
|
40
|
+
|
41
|
+
private let textCell = UITableViewCell()
|
42
|
+
|
43
|
+
private let textField = UITextView()
|
44
|
+
|
45
|
+
// 講義開始時間
|
46
|
+
|
47
|
+
private let textCell2 = UITableViewCell()
|
48
|
+
|
49
|
+
private let textField2 = UITextField()
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
override func viewDidLoad() {
|
54
|
+
|
55
|
+
super.viewDidLoad()
|
56
|
+
|
57
|
+
// titleCellへtitleFieldを子画面として登録
|
58
|
+
|
59
|
+
if (self.titleField.superview == nil) {
|
60
|
+
|
61
|
+
self.titleCell.contentView.addSubview(self.titleField)
|
62
|
+
|
63
|
+
self.titleCell.addTextEditor(self.titleField)
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
// textCellへtextFieldを子画面として登録
|
68
|
+
|
69
|
+
if (self.textField.superview == nil) {
|
70
|
+
|
71
|
+
self.textCell.contentView.addSubview(self.textField)
|
72
|
+
|
73
|
+
self.textCell.addTextEditor(self.textField)
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
// textCell2へtextField2を子画面として登録
|
78
|
+
|
79
|
+
if (self.textField2.superview == nil) {
|
80
|
+
|
81
|
+
self.textCell2.contentView.addSubview(self.textField2)
|
82
|
+
|
83
|
+
self.textCell2.addTextEditor(self.textField2)
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
override func didReceiveMemoryWarning() {
|
92
|
+
|
93
|
+
super.didReceiveMemoryWarning()
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
// セクション数を返す
|
100
|
+
|
101
|
+
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
102
|
+
|
103
|
+
return 3
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
// セクションごとの項目数を返す
|
110
|
+
|
111
|
+
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
112
|
+
|
113
|
+
return 1
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// 項目用のセルを返す
|
120
|
+
|
121
|
+
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
122
|
+
|
123
|
+
if (indexPath.section == 0) {
|
124
|
+
|
125
|
+
return self.titleCell
|
126
|
+
|
127
|
+
}else if (indexPath.section == 1){
|
128
|
+
|
129
|
+
return self.textCell
|
130
|
+
|
131
|
+
}else{
|
132
|
+
|
133
|
+
return self.textCell2
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
// ヘッダー
|
142
|
+
|
143
|
+
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
144
|
+
|
145
|
+
if (section == 0) {
|
146
|
+
|
147
|
+
return "講義名"
|
148
|
+
|
149
|
+
}else if (section == 1){
|
150
|
+
|
151
|
+
return "講義内容"
|
152
|
+
|
153
|
+
}else{
|
154
|
+
|
155
|
+
return "講義開始時間"
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// 項目ごとの高さ
|
164
|
+
|
165
|
+
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
|
166
|
+
|
167
|
+
if (indexPath.section == 0) {
|
168
|
+
|
169
|
+
return 30
|
170
|
+
|
171
|
+
}else if (indexPath.section == 1){
|
172
|
+
|
173
|
+
return 100
|
174
|
+
|
175
|
+
}else{
|
176
|
+
|
177
|
+
return 30
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
extension UITableViewCell {
|
184
|
+
|
185
|
+
// subViewをcontentViewプロパティに登録
|
186
|
+
|
187
|
+
func addTextEditor(subView:UIView) {
|
188
|
+
|
189
|
+
self.contentView.addSubview(subView)
|
190
|
+
|
191
|
+
self.selectionStyle = UITableViewCellSelectionStyle.None
|
192
|
+
|
193
|
+
subView.setTranslatesAutoresizingMaskIntoConstraints(false)
|
194
|
+
|
195
|
+
self.contentView.addConstraint(NSLayoutConstraint(item:subView, attribute:.Left,relatedBy:.Equal, toItem:self.contentView, attribute:.Left, multiplier:1, constant:0))
|
196
|
+
|
197
|
+
self.contentView.addConstraint(NSLayoutConstraint(item:subView, attribute:.Right,relatedBy:.Equal, toItem:self.contentView, attribute:.Right, multiplier:1, constant:0))
|
198
|
+
|
199
|
+
self.contentView.addConstraint(NSLayoutConstraint(item:subView, attribute:.Top,relatedBy:.Equal, toItem:self.contentView, attribute:.Top, multiplier:1, constant:5))
|
200
|
+
|
201
|
+
self.contentView.addConstraint(NSLayoutConstraint(item:subView, attribute:.Bottom,relatedBy:.Equal, toItem:self.contentView, attribute:.Bottom, multiplier:1, constant:-5))
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
```
|