質問編集履歴
4
書式の改善と写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,6 +154,34 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
-
![イメージ説明](9
|
157
|
+
![イメージ説明](aae9b646ceeadc2d6f773bd38a658bb6.png)
|
158
158
|
|
159
|
+
```swift
|
160
|
+
|
161
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
162
|
+
|
163
|
+
return kei.count
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
```swift
|
170
|
+
|
171
|
+
for textField in textFields {
|
172
|
+
|
173
|
+
self.kei.append(textField.text!)
|
174
|
+
|
175
|
+
}
|
176
|
+
|
159
|
-
|
177
|
+
self.mytableView.reloadData()
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
以下の部分を訂正したことによってcell追加をタップして入力させることができるようになったのですが理想としてはcell追加の上に入力した内容が反映されるようにしたいです。
|
184
|
+
|
185
|
+
**イメージとしてはこのようにしたいです。**
|
186
|
+
|
187
|
+
![![イメージ説明](11a28618dbb717d32cbc6c50c9054a0a.png)](4a6755f9c4eb324bac1c40dfbdd19f5f.png)
|
3
スクショの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,6 +154,6 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
-
![イメージ説明](f
|
157
|
+
![イメージ説明](92e2f0d84a264ebd9a8fc2d6ec93819e.png)
|
158
158
|
|
159
|
-
|
159
|
+
入力した内容がtableViewに反映されないなくて困っています
|
2
写真の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -118,6 +118,8 @@
|
|
118
118
|
|
119
119
|
self.present(alert, animated: true, completion: nil)
|
120
120
|
|
121
|
+
return cell
|
122
|
+
|
121
123
|
}
|
122
124
|
|
123
125
|
|
@@ -149,3 +151,9 @@
|
|
149
151
|
|
150
152
|
|
151
153
|
tableView外にボタンを設置してそこからアラートテキストを呼び出して入力した内容をtableViewに反映させることはできるのですがtableView内のテキストをタップしてデータを反映させることがどうしても分からないので教えていただきたいです。
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
![イメージ説明](f7aac353ce2ba2508ad57541de4c51b7.png)
|
158
|
+
|
159
|
+
以下の部分でエラー起きたのですがどこを直せばいいか分からなく困っています
|
1
アラートテキストを表示させるためのコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
44
44
|
|
45
|
-
let cell = UITableViewCell();
|
45
|
+
let cell = UITableViewCell();
|
46
46
|
|
47
47
|
cell.textLabel?.text = kei[indexPath.row]
|
48
48
|
|
@@ -52,6 +52,78 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath) -> UITableViewCell {
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
// OKボタンの設定
|
64
|
+
|
65
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
66
|
+
|
67
|
+
(action:UIAlertAction!) -> Void in
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// OKを押した時入力されていたテキストを表示
|
72
|
+
|
73
|
+
if let textFields = alert.textFields {
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
78
|
+
|
79
|
+
for textField in textFields {
|
80
|
+
|
81
|
+
print(textField.text!)
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
})
|
88
|
+
|
89
|
+
alert.addAction(okAction)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// キャンセルボタンの設定
|
94
|
+
|
95
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
96
|
+
|
97
|
+
alert.addAction(cancelAction)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
// テキストフィールドを追加
|
102
|
+
|
103
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
104
|
+
|
105
|
+
textField.placeholder = "テキスト"
|
106
|
+
|
107
|
+
})
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// アラートを画面に表示
|
118
|
+
|
119
|
+
self.present(alert, animated: true, completion: nil)
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
55
127
|
override func didReceiveMemoryWarning() {
|
56
128
|
|
57
129
|
super.didReceiveMemoryWarning()
|
@@ -60,13 +132,13 @@
|
|
60
132
|
|
61
133
|
}
|
62
134
|
|
135
|
+
|
136
|
+
|
63
137
|
|
64
138
|
|
65
139
|
|
66
140
|
|
67
141
|
}
|
68
|
-
|
69
|
-
|
70
142
|
|
71
143
|
```
|
72
144
|
|