2015-03-31 101 views
0

我想在倒計時結束時停止使用按鈕。Swift - 禁止使用按鈕

class FirstViewController: UIViewController { 

    var scoreTemporaire : Int = 0 


    @IBOutlet weak var afficheurScore: UILabel! 

    @IBAction func boutonPlus(sender: UIButton) { 

      scoreTemporaire = scoreTemporaire + 1 
      afficheurScore.text = "\(scoreTemporaire)" 

     } 


    override func viewDidLoad() { 
     super.viewDidLoad() 
     //calling the wait function 
     self.callForWait() 
    } 

    func callForWait(){ 
     //setting the delay time 60secs. 
     let delay = 12 * Double(NSEC_PER_SEC) 
     let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) 
     dispatch_after(time, dispatch_get_main_queue()) { 
      //call the method which have the steps after delay. 
      self.stepsAfterDelay() 
     } 
    } 


    func stepsAfterDelay(){ 
     let score = scoreTemporaire 
     afficheurScore.text = "\(score)" 

    } 

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

當延遲已經過去了,在標籤(afficheurScore),但得分appairs當你reclick按鈕(boutonPlus),scoreTemporaire上去。我想停止觸摸按鈕的可能性。

回答

0

只需設置

myButton.enabled = false 

你應該從情節串連圖板連接的按鈕,你的代碼中,你實際上是與UILabel做了同樣的方式。 上面的代碼禁用了按鈕。

+0

完美!謝謝 ! – 2015-03-31 09:30:11