2017-03-08 7 views
-2

나는 가장 쉬운 앱을 만들려고 애썼지 만 제대로 작동하지 않습니다. 이 앱에는 두 개의 버튼이 있습니다. 하나는 짧은 소리를 내고 다른 하나는 기부 버튼입니다. 나는 소음을 작동시킬 수는 있지만 링크 나 그 반대는 아니거나 둘 다가 아닙니다. 그리고 재정의 중 하나가 오류가 계속되고 나는 왜 애플 리케이션을 구축 할 수 있도록 코멘트로 넣어 이유를 모르겠다. 오지 않는 오류는 단어 대체를 제거하도록 요청한다는 것입니다. 여기에 코드입니다 :Xcode 8.2.1 계속해서 출력 오류가 발생하려고 시도합니다.

여기
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&currency_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

시도'FUNC 기부 @IBAction (_ 보낸 사람 : 어떤을) 당신이 didReceiveMemoryWarning의 주석을 해제 할 때 {...}'또한 확인하면 확인 돈 '다시 만들 수있는 리소스를 없앱니다.' – Magnas

+0

@gibou'buttonTapped' 메서드가 예상대로 호출되는 중입니까? 인터페이스 빌더에서 컨트롤러의 클래스가'ViewController'로 설정되어 있는지 확인할 수 있습니까? 그것은 당신이'ViewController' 클래스의 인스턴스가 아닌 모든 객체에 컨트롤러 이벤트를 보내는 것 같습니다. –

+0

조언을 해 주셔서 감사합니다. – gibou

답변

1

정확히 응용 프로그램이 작동을 멈 춥니 다?

버튼 중 하나와 같은 UI 요소와 상호 작용할 때 발생합니까?

UI에 "기부"버튼이 있다고 가정하고 있습니다 ... 버튼에서 작업으로의 연결이 올바르게 연결되어 있는지 확인하십시오.

배선을 다시 확인하는 가장 쉬운 방법 중 하나는 인터페이스 빌더 자체에서하는 것입니다. 연결 관리자 버튼을
클릭 : 어떤 ! 기호에 대한

Connections Inspector

검색합니다. 있는 경우 연결을 삭제하고 다시 만드십시오.

위의 내용이 도움이되지 않으면 프로젝트를 공유하여 디버깅을 도와주세요.

합니다 (didReceiveMemoryWarning 재정에 대해서는, 안전하게 지금 삭제할 수 있습니다.)

+0

의견을 보내 주셔서 감사합니다. 그것이 문제였습니다. 프로그램을하지 않았거나 잊어 버렸을 수도있는 또 다른 행동이있었습니다. 이제 작동합니다! 다시 한번 감사합니다! – gibou

+0

문제 없습니다. 답변 (http://stackoverflow.com/help/someone-answers) 및 행복한 코딩을 수락하십시오! –

관련 문제