質問編集履歴
2
最初に質問した時は次のステップ分まで入っていました。そこで、「編集」でその部分を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
**> 問題を修正しました。**
|
2
|
+
|
1
3
|
「世界一受けたい iPhoneアプリ開発の授業 Chapter7-2
|
2
4
|
|
3
5
|
四択検定アプリを作ろう」を参考にしてcsvファイルを読み込み第2問を表示するところまでは行ったのですが、第2問は瞬間で消えて第1問に表示が戻ってしまいます。
|
@@ -14,20 +16,20 @@
|
|
14
16
|
|
15
17
|
ご教示頂ければ幸いです。コードとスクリーンショットは下記のとおりです。
|
16
18
|
|
19
|
+
最初に質問した時は次のステップ分まで入っていました。そこで、「編集」でその部分を修正しました。
|
20
|
+
|
17
21
|
|
18
22
|
|
19
23
|
**私のコード**
|
20
24
|
|
21
25
|
|
22
26
|
|
23
|
-
```
|
27
|
+
``` MondaiViewController.swift
|
24
28
|
|
25
29
|
// Mondai01
|
26
30
|
|
27
31
|
//
|
28
32
|
|
29
|
-
//
|
30
|
-
|
31
33
|
|
32
34
|
|
33
35
|
import UIKit
|
@@ -66,7 +68,7 @@
|
|
66
68
|
|
67
69
|
var correctCount = 0 //正解をカウントする変数
|
68
70
|
|
69
|
-
let total = 10
|
71
|
+
// let total = 10 //出題数を管理する変数
|
70
72
|
|
71
73
|
var nextBtn = UIButton()
|
72
74
|
|
@@ -92,6 +94,8 @@
|
|
92
94
|
|
93
95
|
|
94
96
|
|
97
|
+
|
98
|
+
|
95
99
|
//csvArrayの0行目を取り出し、カンマを区切りとしてmondaiArrayに格納
|
96
100
|
|
97
101
|
mondaiArray = csvArray[mondaiCount].components(separatedBy: ",")
|
@@ -108,6 +112,8 @@
|
|
108
112
|
|
109
113
|
|
110
114
|
|
115
|
+
|
116
|
+
|
111
117
|
//テキストビューに自動でキーボード表示
|
112
118
|
|
113
119
|
kaitouField.becomeFirstResponder()
|
@@ -124,6 +130,8 @@
|
|
124
130
|
|
125
131
|
kaitouField.placeholder = "マイクで問題を読む"
|
126
132
|
|
133
|
+
|
134
|
+
|
127
135
|
}
|
128
136
|
|
129
137
|
|
@@ -176,7 +184,13 @@
|
|
176
184
|
|
177
185
|
}
|
178
186
|
|
187
|
+
|
188
|
+
|
179
|
-
|
189
|
+
func btn02Action(_ sender: UIButton) {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
180
194
|
|
181
195
|
func nextQuestion(){
|
182
196
|
|
@@ -186,74 +200,88 @@
|
|
186
200
|
|
187
201
|
mondaiCount += 1
|
188
202
|
|
189
|
-
|
190
|
-
|
191
203
|
//mondaiArrayに格納されている問題配列を削除
|
192
204
|
|
193
205
|
mondaiArray.removeAll()
|
194
206
|
|
195
|
-
|
196
|
-
|
197
|
-
// //if-else文を追加。mondaiCountがtotalに達したら画面遷移
|
198
|
-
|
199
|
-
if mondaiCount < total{
|
200
|
-
|
201
|
-
|
207
|
+
//csvArrayから次の問題配列をmondaiArrayに格納
|
202
|
-
|
208
|
+
|
203
|
-
|
209
|
+
mondaiArray = csvArray[mondaiCount+1].components(separatedBy: ",")
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
//問題数ラベル、問題表示TextView、選択肢ボタンに文字をセット
|
214
|
+
|
215
|
+
mondaiNumberLabel.text = "第\(mondaiCount+1)問"
|
216
|
+
|
217
|
+
mondaiField.text = mondaiArray[0]
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
print ("ここまで来たddd")
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
//// 前回の質問に入っていた次のステップに進むためのif文ですので、CommentOutしました。
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
//if-else文を追加。mondaiCountがtotalに達したら画面遷移
|
230
|
+
|
231
|
+
// if mondaiCount == total {
|
232
|
+
|
233
|
+
//
|
234
|
+
|
235
|
+
// //Stroyboard SegueのIdentifierを引数に設定して画面遷移
|
236
|
+
|
237
|
+
// performSegue(withIdentifier: "score", sender: nil)
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
// }
|
242
|
+
|
243
|
+
//
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
//else{
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
print ("ここまで来たeee")
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//正誤表示画像を隠す
|
258
|
+
|
259
|
+
judgeImageView.isHidden = true
|
260
|
+
|
261
|
+
//nextQuestionメソッドを呼び出す
|
262
|
+
|
263
|
+
nextQuestion()
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
print ("ここまで来たfff")
|
204
268
|
|
205
269
|
|
206
270
|
|
207
|
-
//問題数ラベル、問題表示TextView、選択肢ボタンに文字をセット
|
208
|
-
|
209
|
-
mondaiNumberLabel.text = "第\(mondaiCount+1)問"
|
210
|
-
|
211
|
-
mondaiField.text = mondaiArray[0]
|
212
|
-
|
213
|
-
print ("ここまで来たddd")
|
214
|
-
|
215
|
-
}else{
|
216
|
-
|
217
|
-
// //Stroyboard SegueのIdentifierを引数に設定して画面遷移
|
218
|
-
|
219
|
-
performSegue(withIdentifier: "score", sender: nil)
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
print ("ここまで来たeee")
|
224
|
-
|
225
271
|
}
|
226
272
|
|
273
|
+
|
274
|
+
|
227
|
-
|
275
|
+
override func didReceiveMemoryWarning() {
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
276
|
+
|
232
|
-
|
233
|
-
|
277
|
+
super.didReceiveMemoryWarning()
|
234
|
-
|
278
|
+
|
235
|
-
|
279
|
+
// Dispose of any resources that can be recreated.
|
236
|
-
|
237
|
-
nextQuestion()
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
print ("ここまで来たhhh")
|
242
280
|
|
243
281
|
}
|
244
282
|
|
245
|
-
override func didReceiveMemoryWarning() {
|
246
|
-
|
247
|
-
super.didReceiveMemoryWarning()
|
248
|
-
|
249
|
-
// Dispose of any resources that can be recreated.
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
283
|
}
|
254
284
|
|
255
|
-
|
256
|
-
|
257
285
|
```
|
258
286
|
|
259
287
|
![イメージ説明](b829b95b37fd5f6384ed635fe068f742.png)
|
@@ -266,15 +294,39 @@
|
|
266
294
|
|
267
295
|
|
268
296
|
|
269
|
-
1. 茶色のもどる ボタンは本のImageを使ったのでもどるになっていますが本来なら次のボタンです。
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
2. printの
|
297
|
+
1. 茶色のもどる ボタンは本のImageを使ったのでもどるになっていますが本来なら次のボタンです。func btn02Actionと結んでいます。
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
2. 一度answerBtnを押し、次に戻るボタン、すなわちbtn02Actionを押した場合の現象は一瞬第2問の数字と問題が現れたあと消えて第1問と問題が現れます。一旦現れた判定の×マークは消えます、その時のprintの結果は下記のとおりです。
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
ここまで来た01
|
306
|
+
|
307
|
+
ここまで来た02
|
308
|
+
|
309
|
+
ここまで来た01
|
310
|
+
|
311
|
+
ここまで来たaaa
|
312
|
+
|
313
|
+
ここまで来た02
|
314
|
+
|
315
|
+
ここまで来た01
|
316
|
+
|
317
|
+
2017-07-09 00:56:10.916377+0900 Mondai01[79881:34645706] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/tomijisuzuki/Library/Developer/CoreSimulator/Devices/ systemgroup.com.apple.configurationprofiles
|
318
|
+
|
319
|
+
2017-07-09 00:56:10.916690+0900 Mondai01[79881:34645706] [MC] Reading from private effective user settings.
|
320
|
+
|
321
|
+
ここまで来たaaa222
|
322
|
+
|
323
|
+
ここまで来たccc
|
324
|
+
|
325
|
+
ここまで来たddd
|
274
326
|
|
275
327
|
ここまで来たeee
|
276
328
|
|
277
|
-
ここまで来た
|
329
|
+
ここまで来たfff
|
278
330
|
|
279
331
|
ここまで来たaaa
|
280
332
|
|
@@ -284,11 +336,17 @@
|
|
284
336
|
|
285
337
|
|
286
338
|
|
339
|
+
|
340
|
+
|
287
341
|
3.もどるボタンを何度押しても一旦第2問が表示され、すぐに1問にもどります。
|
288
342
|
|
289
343
|
|
290
344
|
|
345
|
+
4.一旦 ここまで来たfff には到達するのですが、何故か元に戻りここまで来たaaa をプリントする原因を承知したいと思います。それがこの質問の主旨です。
|
346
|
+
|
347
|
+
|
348
|
+
|
291
|
-
|
349
|
+
5.開発環境は下記のとおりです。
|
292
350
|
|
293
351
|
MacBookPro
|
294
352
|
|
1
最初の質問には次のステップまで含んでいたので、それを取り除いて問題箇所のみに論を絞りました。
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|