2016-05-24 198 views
-1

因此,我擁有的代碼通過一個按鈕連接到故事板。該按鈕可以發出一種叫做笑聲的效果。但是當按下按鈕時。應用程序崩潰,並將這個錯誤「主題1:信號SIGABRTXcode Swift - 按下按鈕時應用程序崩潰

// 
    // ViewController.swift 
    // LaLaLaughing 
    // 
    // Created by MightyShin on 5/16/16. 
    // Copyright © 2016 Reverze. All rights reserved. 
    // 

    import UIKit 
    import AVFoundation 

    class ViewController: UIViewController { 

    var audioPlayer = AVAudioPlayer() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 


    @IBAction func LaughSound(sender: AnyObject) { 

     var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Laughing", ofType: "mp3")!) 

     do { 
      // Preperation 
      try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) 
     } catch _ { 
     } 
     do { 
      try AVAudioSession.sharedInstance().setActive(true) 
     } catch _ { 
     } 

     // Play the sound 
     do { 
      audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound) 
     } catch _{ 
     } 

     audioPlayer.prepareToPlay() 
     audioPlayer.play() 
    } 
} 
+1

顯示完整的stracktrace。 – trojanfoe

+1

什麼是stracktrace? – RapidReverse

+1

@RapidReverse複製和粘貼Xcode調試器在應用程序崩潰時顯示的所有內容 –

回答

1

SIGABRT通常與連​​接涉及檢查所有的出口和動作,如果你做了插座,然後可能會出現的問題改變了它的類型說文本框到TextView的,或更名EG-nameDoctorLabel到doctorNameLabel。

你也可能手工編寫的IBoutlets和IbActions和忘記他們各自的對象的故事板鏈接。

同時檢查是否有一個填充你的IBAction左邊的灰色圓點

檢查連接檢查器中的連接。

+3

這是一條評論,而不是答案。 – trojanfoe

+0

@trojanfoe。他無法評論 – UsamaMan

相關問題