我可能试图制作最简单的应用程序,但我无法让它工作。该应用程序有两个按钮。一个发出短暂的噪音,另一个是捐赠按钮。我可以让噪音工作,但不是链接或反之亦然。其中一个覆盖不断变成一个错误,我不知道为什么所以我把它作为评论,以便应用程序将构建。出现的错误是它要求我删除单词覆盖。这是代码:
import UIKit
import AVFoundation
class ViewController: UIViewController {
let soundFilenames = ["WeahV2"]
var audioPlayers = [AVAudioPlayer]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Set up audio player
for sound in soundFilenames {
do {
// Try to do something
let url = NSURL(fileURLWithPath: Bundle.main.path( forResource: sound, ofType: "mp3")!)
let audioPlayer = try AVAudioPlayer(contentsOf: url as URL)
audioPlayers.append(audioPlayer)
}
catch {
//catch the error that is thrown
audioPlayers.append(AVAudioPlayer())
}
}
}
//override func didReceiveMemoryWarning() {
// super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
//}
@IBAction func buttonTapped(_ sender: UIButton) {
// get the audio player that corresponds with the button tapped
let audioPlayer = audioPlayers[sender.tag]
audioPlayer.play()
}
@IBAction func Donate( sender: AnyObject) {
if let url = URL(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5Q29GRLXF4W9C&lc=CA&item_name=BiBoCo¤cy_code=CAD&bn=PP-DonationsBF%3Abtn_donateCC_LG.gif%3ANonHosted") {
UIApplication.shared.open(url, options: [:]) {
boolean in
// do something with the boolean
}
}
}
}
这是输出信息(可能是我所知道的所有错误,我不知道如何理解它):
2017-03-08 17:10:34.256692 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (1): skipping input stream 0 0 0x0 2017-03-08 17:10:36.241162 The Weah[22117:1032029] [aqme] 177: timed out after 0.012s (126 127); suspension count=0 (IOSuspensions: ) 2017-03-08 17:10:36.264895 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (128): skipping input stream 0 0 0x0 2017-03-08 17:10:36.498 The Weah[22117:1030634] -[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20 2017-03-08 17:10:37.037 The Weah[22117:1030634] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20' *** First throw call stack: ( 0 CoreFoundation 0x000000010ca9dd4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010c4ff21e objc_exception_throw + 48 2 CoreFoundation 0x000000010cb0df04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010ca23005 ___forwarding___ + 1013 4 CoreFoundation 0x000000010ca22b88 _CF_forwarding_prep_0 + 120 5 UIKit 0x000000010cec38bc -[UIApplication sendAction:to:from:forEvent:] + 83 6 UIKit 0x000000010d049c38 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x000000010d049f51 -[UIControl _sendActionsForEvents:withEvent:] + 444 8 UIKit 0x000000010d048e4d -[UIControl touchesEnded:withEvent:] + 668 9 UIKit 0x000000010cf31545 -[UIWindow _sendTouchesForEvent:] + 2747 10 UIKit 0x000000010cf32c33 -[UIWindow sendEvent:] + 4011 11 UIKit 0x000000010cedf9ab -[UIApplication sendEvent:] + 371 12 UIKit 0x000000010d6cc72d __dispatchPreprocessedEventFromEventQueue + 3248 13 UIKit 0x000000010d6c5463 __handleEventQueue + 4879 14 CoreFoundation 0x000000010ca42761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 15 CoreFoundation 0x000000010ca2798c __CFRunLoopDoSources0 + 556 16 CoreFoundation 0x000000010ca26e76 __CFRunLoopRun + 918 17 CoreFoundation 0x000000010ca26884 CFRunLoopRunSpecific + 420 18 GraphicsServices 0x00000001116eda6f GSEventRunModal + 161 19 UIKit 0x000000010cec1c68 UIApplicationMain + 159 20 The Weah 0x000000010bbb56bf main + 111 21 libdyld.dylib 0x0000000111ce168d start + 1 22 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
答案 0 :(得分:1)
当应用程序完全停止工作时?
当您与UI元素交互时是否会发生这种情况,例如其中一个按钮?
我假设有一个" Donate" UI上的按钮...确保从按钮到操作的连接已正确连接。
仔细检查接线的最简单方法之一是接口构建器本身 单击 Connections Inspector 按钮:
搜索任何!
个符号。如果有,请删除连接并重新创建。
如果上述方法没有解决问题,请分享您的项目,以便我可以帮助您进行调试。
(关于didReceiveMemoryWarning
覆盖,您现在可以安全地删除它。)