2015-08-31 29 views
0

我有原型單元格,並且在這個單元格中有一個UIButton;所以我需要從按鈕執行一個segue到其他控制器,而不是從單元格。我試圖創建一個出口@IBOutlet var button: UIButton!和使用performSegueWithIdentifier()方法在TabeViewCell中觸發Segue從UIButton

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{ 
    self.performSegueWithIdentifier("toSecondController", sender: button) 
    tableView.deselectRowAtIndexPath(indexPath, animated: true) 
} 

,但我不知道如何設置prepareForSegue()方法......我想這

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) 
{ 
    if segue.identifier == "toSecondController" 
    { 
     if let indexPath = sender as? UIButton//tableView.indexPathForSelectedRow() 
     { 
      let controller = segue.destinationViewController as! CoriViewController 
      controller.coriSquadra = DataManager.sharedInstance.arrayCori[indexPath.row] 
     } 
    } 
} 

我也讀到一個解決方案將實施一個協議,但我是一個初學者,我需要一步一步的指導。 希望有人能幫助我!

回答

0

你在正確的軌道上。在您的tableviewcontroller定義

@IBAction func clicked(){ 
    self.performSegueWithIdentifier("toSecondController", sender: button) 
} 

你可以保持

tableView.deselectRowAtIndexPath(indexPath, animated: true) 

線在您的didSelectRowAtIndexPath方法。別忘了將你的ibaction連接到故事板上的按鈕。

+0

非常感謝!但我也有一個與segue的問題「uibutton沒有名爲行的行(第8行)! –

+0

更改發件人:按鈕發件人:自己 – Roosh

+0

對不起,但我無法使prepareForSegue工作...你能幫助我用這個其他的方法?Xcode仍然顯示以前的錯誤 –

相關問題