我正在关注udacity的课程,试图学习如何使用xcode和swift制作iPhone应用程序。当我点击应用程序中的按钮时,我正在播放音频文件。每次我点击它,我都会收到以下错误消息:
in recordAudio
2015-04-05 14:42:18.124 Pitch Perfect[18544:1141273] -[Pitch_Perfect.PlaySoundsViewController slowAudio:]: unrecognized selector sent to instance 0x7f8174001760
2015-04-05 14:42:18.135 Pitch Perfect[18544:1141273] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Pitch_Perfect.PlaySoundsViewController slowAudio:]: unrecognized selector sent to instance 0x7f8174001760'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ab57a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c6afbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ab5ed1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010aab69dc ___forwarding___ + 988
4 CoreFoundation 0x000000010aab6578 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010b3eba22 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010b4f2e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010b4f221f -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x000000010b431b68 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x000000010b432493 -[UIWindow sendEvent:] + 683
10 UIKit 0x000000010b3fefb1 -[UIApplication sendEvent:] + 246
11 UIKit 0x000000010b40c227 _UIApplicationHandleEventFromQueueEvent + 17700
12 UIKit 0x000000010b3e723c _UIApplicationHandleEventQueue + 2066
13 CoreFoundation 0x000000010aa8cc91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010aa82b5d __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010aa82194 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010aa81bc6 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010eb2da58 GSEventRunModal + 161
18 UIKit 0x000000010b3ea580 UIApplicationMain + 1282
19 Pitch Perfect 0x000000010a61d42e top_level_code + 78
20 Pitch Perfect 0x000000010a61d46a main + 42
21 libdyld.dylib 0x000000010ce8b145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
这是我播放音频的代码。我似乎无法弄清楚出了什么问题。我一直在完全遵循所有步骤。
// PlaySoundsViewController.swift
// Pitch Perfect
import UIKit
import AVFoundation
class PlaySoundsViewController: UIViewController {
var audioPlayer:AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if var filePath = NSBundle.mainBundle().pathForResource("movie_quote",ofType: "mp3"){
var filePathUrl = NSURL.fileURLWithPath(filePath)
audioPlayer = AVAudioPlayer(contentsOfURL: filePathUrl, error: nil)
} else{
println("the filepath is empty")
}
}
@IBAction func playSlowAudio(sender: UIButton) {
// Play audio slowly
audioPlayer.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
有人可以帮我找到问题吗?我是应用程序开发的新手。
答案 0 :(得分:1)
似乎你有一个名为slowAudio的方法:某个地方,但是你的控制器中没有实现该方法;可能连接到IB中的按钮?右键单击故事板(或xib)中的按钮以显示黑色窗口,以查看是否存在与名为slowAudio:的方法的连接。如果有,请单击小“x”删除连接。