2016-02-25 68 views
-1

我對我的應用程序倒數計時器啓動從15這倒計時的工作是我的代碼:製作倒數計時器時出現Swift Signal SIGABRT錯誤?

// 


import UIKit 

class ViewController2: UIViewController { 
    @IBOutlet weak var Timer: UILabel! 


    var countd = 15 








// 
// 
    override func viewDidLoad() { 

    super.viewDidLoad() 
    let time = NSTimer(timeInterval: 1.0, target: self, selector: "updateCounter", userInfo: nil, repeats: true) 
    Timer.text = String(countd) 
NSRunLoop.mainRunLoop().addTimer(time, forMode: NSDefaultRunLoopMode) 

    } 

    func updateCounter(timer: NSTimer) { 


     Timer.text = String(countd) 

     if (countd > 0){ 

      Timer.text = String(countd--) 
      Timer.text = String(countd) 
     } 

    } 





     // Do any additional setup after loading the view. 


    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. 
    } 
    */ 

} 

然而,當我運行它,只要我得到與計時器我的一部分看到標籤flash 15一秒鐘,但它立即崩潰與SIGABRT錯誤。我能做什麼?

回答

0

變化

selector: "updateCounter" 

selector: "updateCounter:" 

請注意,雨燕2.2將很難犯這個錯誤(編譯器會發出警告),而在斯威夫特3將成爲不可能(字符串文字選擇器語法將變得非法)。如果您不理解字符串文字選擇器語法,則可能要更新到Swift 2.2 現在