質問編集履歴
2
コードとタイトル
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ボタン
|
1
|
+
table cellでは一つのボタンで再生と停止というのはできないのでしょうか?
|
test
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
セルごとに異なる曲を再生したく、プロジェクトに4曲(sound01〜sound04)を保存して、以下のコードを書きました。
|
2
2
|
|
3
|
-
そして『Play』ボタンを押すと再生
|
3
|
+
そして『Play』ボタンを押すと再生して『Pause』と表示され、『Pause』を押すとボタンが『Play』に変わるようにしたいのですが、以下のエラーが出ます。
|
4
|
+
|
5
|
+
|
6
|
+
|
4
|
-
|
7
|
+
エラー内容①:
|
8
|
+
|
9
|
+
The btnPlayPause outlet from the SecondViewController to the UIButton is invalid. Outlets cannot be connected to repeating content.
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
エラー内容②:
|
14
|
+
|
5
|
-
|
15
|
+
Use of unresolved identifier 'audioPath'
|
6
|
-
|
7
|
-
|
8
16
|
|
9
17
|
|
10
18
|
|
@@ -24,9 +32,11 @@
|
|
24
32
|
|
25
33
|
class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, CustomTableViewCellDelegate {
|
26
34
|
|
35
|
+
|
36
|
+
|
27
|
-
|
37
|
+
var player = AVAudioPlayer()
|
28
|
-
|
29
|
-
|
38
|
+
|
39
|
+
|
30
40
|
|
31
41
|
let imageNames = ["futako.jpg", "yokado.jpg", "fran.jpg", "zikken.jpg"]
|
32
42
|
|
@@ -58,6 +68,18 @@
|
|
58
68
|
|
59
69
|
// Do any additional setup after loading the view, typically from a nib.
|
60
70
|
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
player = AVAudioPlayer(contentsOfURL: audioPath, error: nil)
|
76
|
+
|
77
|
+
player.prepareToPlay()
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
61
83
|
}
|
62
84
|
|
63
85
|
|
@@ -72,6 +94,32 @@
|
|
72
94
|
|
73
95
|
|
74
96
|
|
97
|
+
|
98
|
+
|
99
|
+
@IBOutlet weak var btnPlayPause: UIButton!
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
@IBAction func btnPlayPause(sender: UIButton) {
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if (player.playing) {
|
108
|
+
|
109
|
+
player.pause()
|
110
|
+
|
111
|
+
btnPlayPause.setTitle("Play", forState: UIControlState.Normal)
|
112
|
+
|
113
|
+
} else {
|
114
|
+
|
115
|
+
player.play()
|
116
|
+
|
117
|
+
btnPlayPause.setTitle("Pause", forState: UIControlState.Normal)
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
|
75
123
|
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
76
124
|
|
77
125
|
return imageNames.count
|
@@ -132,13 +180,13 @@
|
|
132
180
|
|
133
181
|
}
|
134
182
|
|
135
|
-
}
|
183
|
+
}
|
136
184
|
|
137
185
|
}
|
138
186
|
|
139
|
-
|
140
|
-
|
141
|
-
|
187
|
+
|
188
|
+
|
189
|
+
|
142
190
|
|
143
191
|
|
144
192
|
|
@@ -148,7 +196,7 @@
|
|
148
196
|
|
149
197
|
import UIKit
|
150
198
|
|
151
|
-
|
199
|
+
|
152
200
|
|
153
201
|
protocol CustomTableViewCellDelegate: class {
|
154
202
|
|
@@ -172,7 +220,9 @@
|
|
172
220
|
|
173
221
|
|
174
222
|
|
175
|
-
@IBOutlet weak var ta
|
223
|
+
@IBOutlet weak var btnPlayPause: UIButton!
|
224
|
+
|
225
|
+
|
176
226
|
|
177
227
|
|
178
228
|
|
@@ -214,15 +264,7 @@
|
|
214
264
|
|
215
265
|
}
|
216
266
|
|
217
|
-
|
218
|
-
|
219
|
-
@IBAction func tapButton(sender: AnyObject) {
|
220
|
-
|
221
|
-
delegate?.selectCellButton(index)
|
222
|
-
|
223
|
-
|
267
|
+
}
|
224
|
-
|
225
|
-
}
|
226
268
|
|
227
269
|
|
228
270
|
|
1
タイトル
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ボタンひとつで音楽を再生・停止したい
|
test
CHANGED
File without changes
|