2014-10-01 28 views
4

我有一個自定義單元格附加到TableViewCell類,並且我有一個按鈕裏面的自定義單元格,我想要乳清我按下按鈕它繼續到另一個視圖控制器,但:斯威夫特 - 塞格從單元格內的按鈕

performSegueWithIdentifier(identifier: String, sender: AnyObject?) 

功能無法識別,如何解決?

編輯:

Screenshot

回答

0

你需要一個自定義類的細胞。在該類中,創建一個@IBAction作爲對按鈕單擊的響應。在那個動作中,執行你的繼續。

+0

我已經做了所有已。 – Abdou023 2014-10-01 14:45:42

+0

請顯示該操作的代碼。 – zisoft 2014-10-01 14:47:06

+0

我更新了我的問題 – Abdou023 2014-10-01 14:55:36

0

如果您使用的界面生成器:

您firstViewController連接到secondViewController - 並創建一個Segue公司標識。

然後你就可以使用

performSegueWithIdentifier(identifier: String, sender: AnyObject?) 
+0

已經這樣做了 – Abdou023 2014-10-01 14:57:46

+0

您的細胞(不是按鈕)連接到secondViewController – derdida 2014-10-01 14:58:52

+0

的問題是不是與連接進行SEGUE,它與識別功能本身。編譯器不接受它。 – Abdou023 2014-10-01 15:03:35

17

-performSegueWithIdentifier:方法UIViewController聲明。所以你不能只在UITableViewCell子類中調用它。

你可以當你在-tableView:cellForRowAtIndexpath:方法產生細胞的動作添加到該按鈕。然後,您可以在該操作方法中調用-performSegueWithIdentifier:方法。這裏是假設例如我們在UITableViewController子類:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell 

    cell.button.addTarget(self, action: "someAction", forControlEvents: .TouchUpInside) 

    return cell 
} 

這裏是操作方法:

func someAction() { 
    self.performSegueWithIdentifier("moveToView", sender: self) 
} 
+0

這解決了我花了幾個小時的問題。謝謝。這是最佳做法嗎?這很容易,而且很有效,所以這是件好事。考慮考慮準備segue將數據傳遞到moveToView – 2015-03-07 22:48:46

+0

請顯示你如何定義你的segue ...因爲它不適合我;( – Arti 2015-10-11 12:47:50