簡體   English   中英

在Button中以NSException類型的未捕獲異常終止

[英]Terminating with uncaught exception of type NSException in Button

我正在創建一個簡單的Tic Tac Toe游戲。

我的playAgain按鈕導致uncaught exception ,我似乎無法弄清楚原因。

var buttonToClear : UIButton
for var i = 0; i < 9; i++ {
    buttonToClear = view.viewWithTag(i) as! UIButton
    buttonToClear.setImage(nil, forState: .Normal)
}

錯誤:

-[TicTacToe.ViewController playAgainButton:]: unrecognized selector sent to instance

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TicTacToe.ViewController playAgainButton:]: unrecognised selector sent to instance

First throw call stack: -[NSObject(NSObject) doesNotRecognizeSelector:]

在“界面構建器”中,單擊playAgainButton,然后單擊右側選項卡欄上的“連接檢查器”按鈕(這是最右側的按鈕)。 現在,在“已發送事件”下查看,您將在此處看到與過時功能的不需要的連接,請將其刪除以解決問題。

如果不是上述情況,則在按鈕點擊時您的代碼中可能有一個不需要的呼叫。

您沒有在TicTacToe ViewController定義playAgainButton方法的主體。

所以做吧

@IBAction func playAgainButton(sender: UIButton) {
    // do your stuff over here
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM