我正在尝试从UITableViewController
中的UIViewController
调用函数。 ViewController
是播放声音的地方,但我想通过选择表格单元格从 SettingsView
更改声音。
ViewController:UIViewController
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBAction func playSound(sender: UIButton) {
playAudio() //Starting Audio
}
设置视图:UITableViewController
var audioPlayer = AVAudioPlayer()
func playAudio(audioName: String ) {
if let audioURL = NSBundle.mainBundle().URLForResource(audioName, withExtension: "mp3") {
audioPlayer = try! AVAudioPlayer(contentsOfURL: audioURL)
audioPlayer.prepareToPlay()
audioPlayer.play()
audioPlayer.numberOfLoops = -1
}
//Standard Fan is Table Cell
if standardFan.accessoryType == .Checkmark {
playAudio("fanpost")
print("Standard")
}
//Alternate Fan is a Table Cell
if alternateFan.accessoryType == .Checkmark {
playAudio("AlternateFan")
print("Alternate")
}
//White Fan is a Table Cell
if whiteFan.accessoryType == .Checkmark {
playAudio("WhiteNoise")
print("White")
}
}