2014-12-13 43 views
0

Xcode 6.1.1 - 我已經用一個按鈕編寫了小應用程序。我在ViewController.swift中編寫了IBAction方法showMessage()。當我試圖連接按鈕和視圖控制器。故事板中的視圖控制器圖標未顯示「已發送事件」---> showMessage方法。無法鏈接Xcode 6.1.1中的無爲和視圖控制器

@IBAction func showMessage() { 
    let alertController = UIAlertController(title: "Welcome to My First App", message: "Hello World", preferredStyle: UIAlertControllerStyle.Alert) 
    alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
    self.presentViewController(alertController, animated: true, completion: nil) 
} 
+0

請顯示您的'IBAction'方法的代碼。 – vacawama 2014-12-13 11:38:51

+0

你確定你將視圖控制器設置爲故事板中的類嗎? – 2014-12-13 11:48:18

+0

@IBAction func showMessage(){ let alertController = UIAlertController(title:「Welcome to My First App」,message:「Hello World」,preferredStyle:UIAlertControllerStyle.Alert) alertController.addAction(UIAlertAction(title:「OK」,風格:UIAlertActionStyle.Default,處理程序:無)) self.presentViewController(alertController,animated:true,completion:nil) } – 2014-12-13 12:11:44

回答

0

你的方法很好。當我嘗試它,它的工作和showMessage確實出現在發送事件。正如@Daniel Nagy在評論中提到的那樣,你應該確保你在Storyboard中正確設置你的課程。

  1. 單擊View Controller頂部的ViewController圖標。
  2. 在右側的Identity Inspector中,將類別設置爲您的視圖控制器的類別。

    enter image description here

+0

0down voteaccept 謝謝。我注意到Module字段是空的。它沒有填寫我的項目名稱,例如「Current - HelloWorld」 – 2014-12-15 05:03:02

0

感謝。我注意到Module字段是空的。它不填寫我的項目名稱,如當前 - HelloWorld