質問編集履歴
6
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -159,75 +159,4 @@
|
|
159
159
|
return indexPath
|
160
160
|
}
|
161
161
|
```
|
162
|
-
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
162
|
+
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
163
|
-
|
164
|
-
**編集したコード**
|
165
|
-
```
|
166
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
167
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
168
|
-
cell.textLabel?.text = kei[indexPath.row]
|
169
|
-
cell.selectionStyle = (kei.count > (indexPath.row + 1)) ? .none : .blue
|
170
|
-
|
171
|
-
if kei.count > (indexPath.row + 1) {
|
172
|
-
cell.isUserInteractionEnabled = false
|
173
|
-
|
174
|
-
}
|
175
|
-
|
176
|
-
return cell
|
177
|
-
}
|
178
|
-
|
179
|
-
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
180
|
-
if kei.count > (indexPath.row + 1) {
|
181
|
-
return nil
|
182
|
-
}
|
183
|
-
return indexPath
|
184
|
-
}
|
185
|
-
```
|
186
|
-
|
187
|
-

|
188
|
-

|
189
|
-

|
190
|
-
```ここに言語を入力
|
191
|
-
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath){
|
192
|
-
|
193
|
-
if kei.count > ([indexPath.row]) {
|
194
|
-
return nil
|
195
|
-
}
|
196
|
-
|
197
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
198
|
-
|
199
|
-
// OKボタンの設定
|
200
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
201
|
-
(action:UIAlertAction!) -> Void in
|
202
|
-
|
203
|
-
// OKを押した時入力されていたテキストを表示
|
204
|
-
if let textFields = alert.textFields {
|
205
|
-
|
206
|
-
// アラートに含まれるすべてのテキストフィールドを調べる
|
207
|
-
for textField in textFields {
|
208
|
-
self.kei.insert(textField.text!, at:0)
|
209
|
-
//self.kei.append(textField.text!)
|
210
|
-
}
|
211
|
-
self.mytableView.reloadData()
|
212
|
-
|
213
|
-
}
|
214
|
-
})
|
215
|
-
alert.addAction(okAction)
|
216
|
-
|
217
|
-
// キャンセルボタンの設定
|
218
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
219
|
-
alert.addAction(cancelAction)
|
220
|
-
|
221
|
-
// テキストフィールドを追加
|
222
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
223
|
-
textField.placeholder = "テキスト"
|
224
|
-
})
|
225
|
-
|
226
|
-
|
227
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
228
|
-
|
229
|
-
// アラートを画面に表示
|
230
|
-
self.present(alert, animated: true, completion: nil)
|
231
|
-
|
232
|
-
}
|
233
|
-
```
|
5
こーどの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -186,4 +186,48 @@
|
|
186
186
|
|
187
187
|

|
188
188
|

|
189
|
-

|
189
|
+

|
190
|
+
```ここに言語を入力
|
191
|
+
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath){
|
192
|
+
|
193
|
+
if kei.count > ([indexPath.row]) {
|
194
|
+
return nil
|
195
|
+
}
|
196
|
+
|
197
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
198
|
+
|
199
|
+
// OKボタンの設定
|
200
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
201
|
+
(action:UIAlertAction!) -> Void in
|
202
|
+
|
203
|
+
// OKを押した時入力されていたテキストを表示
|
204
|
+
if let textFields = alert.textFields {
|
205
|
+
|
206
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
207
|
+
for textField in textFields {
|
208
|
+
self.kei.insert(textField.text!, at:0)
|
209
|
+
//self.kei.append(textField.text!)
|
210
|
+
}
|
211
|
+
self.mytableView.reloadData()
|
212
|
+
|
213
|
+
}
|
214
|
+
})
|
215
|
+
alert.addAction(okAction)
|
216
|
+
|
217
|
+
// キャンセルボタンの設定
|
218
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
219
|
+
alert.addAction(cancelAction)
|
220
|
+
|
221
|
+
// テキストフィールドを追加
|
222
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
223
|
+
textField.placeholder = "テキスト"
|
224
|
+
})
|
225
|
+
|
226
|
+
|
227
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
228
|
+
|
229
|
+
// アラートを画面に表示
|
230
|
+
self.present(alert, animated: true, completion: nil)
|
231
|
+
|
232
|
+
}
|
233
|
+
```
|
4
画像の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -185,4 +185,5 @@
|
|
185
185
|
```
|
186
186
|
|
187
187
|

|
188
|
-

|
188
|
+

|
189
|
+

|
3
コードとが画像の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -134,9 +134,7 @@
|
|
134
134
|
**やりたいこと**
|
135
135
|
他の人の質問を参考にしてcellをタップするとアラートテキストが表示され入力出来るようになったのですが理想としては[cell 追加]以外はタップしても何も入力できないようにしたいです。
|
136
136
|
|
137
|
-
!明]
|
138
137
|
|
139
|
-

|
140
138
|
|
141
139
|
```ここに言語を入力
|
142
140
|
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
|
@@ -161,4 +159,30 @@
|
|
161
159
|
return indexPath
|
162
160
|
}
|
163
161
|
```
|
164
|
-
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
162
|
+
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
163
|
+
|
164
|
+
**編集したコード**
|
165
|
+
```
|
166
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
167
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
168
|
+
cell.textLabel?.text = kei[indexPath.row]
|
169
|
+
cell.selectionStyle = (kei.count > (indexPath.row + 1)) ? .none : .blue
|
170
|
+
|
171
|
+
if kei.count > (indexPath.row + 1) {
|
172
|
+
cell.isUserInteractionEnabled = false
|
173
|
+
|
174
|
+
}
|
175
|
+
|
176
|
+
return cell
|
177
|
+
}
|
178
|
+
|
179
|
+
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
180
|
+
if kei.count > (indexPath.row + 1) {
|
181
|
+
return nil
|
182
|
+
}
|
183
|
+
return indexPath
|
184
|
+
}
|
185
|
+
```
|
186
|
+
|
187
|
+

|
188
|
+

|
2
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -136,4 +136,29 @@
|
|
136
136
|
|
137
137
|
!明]
|
138
138
|
|
139
|
-

|
139
|
+

|
140
|
+
|
141
|
+
```ここに言語を入力
|
142
|
+
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
|
143
|
+
|
144
|
+
switch indexPath.row {
|
145
|
+
case 0:
|
146
|
+
return indexPath
|
147
|
+
// 選択不可にしたい場合は"nil"を返す
|
148
|
+
case 1:
|
149
|
+
return nil
|
150
|
+
default:
|
151
|
+
return indexPath
|
152
|
+
}
|
153
|
+
|
154
|
+
}
|
155
|
+
|
156
|
+
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
157
|
+
|
158
|
+
if kei.count > (indexPath.row + 1) {
|
159
|
+
return nil
|
160
|
+
}
|
161
|
+
return indexPath
|
162
|
+
}
|
163
|
+
```
|
164
|
+
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
1
画像の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -132,4 +132,8 @@
|
|
132
132
|
```
|
133
133
|
|
134
134
|
**やりたいこと**
|
135
|
-
他の人の質問を参考にしてcellをタップするとアラートテキストが表示され入力出来るようになったのですが理想としては[cell 追加]以外はタップしても何も入力できないようにしたいです。
|
135
|
+
他の人の質問を参考にしてcellをタップするとアラートテキストが表示され入力出来るようになったのですが理想としては[cell 追加]以外はタップしても何も入力できないようにしたいです。
|
136
|
+
|
137
|
+
!明]
|
138
|
+
|
139
|
+

|