回答編集履歴
3
説明追加
test
CHANGED
@@ -76,7 +76,9 @@
|
|
76
76
|
|
77
77
|
}
|
78
78
|
|
79
|
-
|
79
|
+
//ここで番号とラベルが一致しているかの確認
|
80
|
+
|
81
|
+
//番号が0だったら、ラベルは”グー”
|
80
82
|
|
81
83
|
print("ナンバー", self.answerNumber)
|
82
84
|
|
2
説明追加
test
CHANGED
@@ -36,13 +36,15 @@
|
|
36
36
|
|
37
37
|
var answerNumber = 0
|
38
38
|
|
39
|
+
//UIButtonのインスタンス生成
|
40
|
+
|
39
41
|
var answerLabel = UILabel()
|
40
42
|
|
41
43
|
|
42
44
|
|
43
45
|
@IBAction func shuffleAction(_ sender: Any) {
|
44
46
|
|
45
|
-
|
47
|
+
//まずラベルのテキスは"最初はぐ~ じゃんけん"
|
46
48
|
|
47
49
|
answerLabel.text = "最初はぐ~ じゃんけん"
|
48
50
|
|
@@ -50,7 +52,11 @@
|
|
50
52
|
|
51
53
|
|
52
54
|
|
55
|
+
//ここで遅延処理
|
56
|
+
|
53
57
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
58
|
+
|
59
|
+
//番号のシャッフル(0~3)
|
54
60
|
|
55
61
|
self.answerNumber = Int(arc4random_uniform(3))
|
56
62
|
|
1
質問者の追加の問いに回答
test
CHANGED
@@ -23,3 +23,61 @@
|
|
23
23
|
}
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
(追加質問の"printではなくLabelでやりたいのですがどうすればいいですか?")への回答
|
30
|
+
|
31
|
+
printでもlabelでも考え方は同じなのであります
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```ここに言語を入力
|
36
|
+
|
37
|
+
var answerNumber = 0
|
38
|
+
|
39
|
+
var answerLabel = UILabel()
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
@IBAction func shuffleAction(_ sender: Any) {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
answerLabel.text = "最初はぐ~ じゃんけん"
|
48
|
+
|
49
|
+
print(answerLabel.text)
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
54
|
+
|
55
|
+
self.answerNumber = Int(arc4random_uniform(3))
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
if self.answerNumber == 0 {
|
60
|
+
|
61
|
+
self.answerLabel.text = "グー"
|
62
|
+
|
63
|
+
} else if self.answerNumber == 1 {
|
64
|
+
|
65
|
+
self.answerLabel.text = "チョキ"
|
66
|
+
|
67
|
+
} else if self.answerNumber == 2 {
|
68
|
+
|
69
|
+
self.answerLabel.text = "パー"
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
print("ナンバー", self.answerNumber)
|
76
|
+
|
77
|
+
print("アンサーラベル", self.answerLabel.text)
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|