我正在尝试了解如何根据Audiokit Docs我的代码上的说明将回调附加到AudioKit上的按钮:
import UIKit
import AudioKit
import AudioKitUI
class ViewController: UIViewController {
let sounds = AKSampler()
@IBOutlet weak var tam: AKButton!
override func viewDidLoad() {
do {
let hiTomFile = try AKAudioFile(readFileName: "hi_tom_D2.wav")
try sounds.loadAudioFiles([hiTomFile])
AudioKit.output = sounds
} catch {
print ("error reading file")
}
do {
try AudioKit.start()
} catch {
AKLog("AudioKit did not start!")
}
// Bad access here!
tam.callback = { button in self.sounds.play() }
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
但是访问不好。关于我做错了什么的提示?
答案 0 :(得分:2)
我能让你的按钮正常工作。你在你的故事板中有一个UIButton,但是我创建了一个通用的UIView,从模块“AudioKitUI”将类改为“AKButton”,然后将它连接到你的“tam”声明,点击它就会运行回调,没有错误。