您好我为自己创建了一个应用程序,我想要计算并在屏幕上显示#。我想使用音量按钮向上和向下计数。我能够在屏幕上创建一个按钮来上下计数,但我想使用物理按钮。我列出了到目前为止我所拥有的内容,但音量按钮似乎无法正常工作。我已经用AVAudioPlayer取代AVAudioSession,希望用滑块控制音量。 我收到错误EXC_BAD_ACCESS(代码= 1,地址= 0x48)
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
@IBOutlet weak var counter: UILabel!
@IBOutlet weak var tapCounterUp: UIButton!
@IBOutlet weak var tapCounterDown: UIButton!
@IBOutlet weak var tapReset: UIButton!
@IBOutlet weak var volumeController: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
//Starts the count at 0
var count : Int = 0
//Adds +1 to Count
@IBAction func buttonUp(_ sender: Any) {
count += 1
counter.text = String(count)
}
//Subtracts -1 to Count
@IBAction func buttonDown(_ sender: Any) {
count -= 1
counter.text = String(count)
}
//Resets the Count to "0"
@IBAction func buttonReset(_ sender: Any) {
count = 0
counter.text = String(count)
}
//Volume Controller
@IBAction func volumeControl(_ sender: UISlider) {
let sliderValue = lroundf(sender.value)
counter.text = "\(sliderValue)"
**// This is were the Error occurs.**
audioPlayer.volume = volumeController.value
}
// End of funtion, don't delete
}