2016-03-02 122 views
-1

我有一個tableView,我做了它的單元格自定義,並添加了一個UIButton到單元格 我想當我按下按鈕彈出一個新的ViewController,並在它的單元格中的文本我點擊了它的按鈕。我不想使用didSelectRowAtIndexPath func,我想在每個單元格中使用按鈕的事件。顯示viewController swift

我試圖使用popOver segue將新按鈕與viewController連接起來,但構建失敗,因爲它是動態的。

請幫忙,並迅速做出答案。 在此先感謝

+0

能告訴你的是你試過的代碼是什麼? –

+0

同意@TimVermeulen,聽起來像你需要看一個委託,告訴你的VC做賽季。 – sschale

+0

@TimVermeulen:我沒有寫任何代碼,因爲我不知道這對我來說是一個新東西,但我試圖將它從storyboard和ctr +從自定義單元格中的按鈕拖放到新的viewcontroller並選擇popover作爲segue類型,我得到了錯誤「Could'n編譯連接」。這就是全部 – RGB

回答

0

您shouls設定目標按鈕的cellForRowAtIndexPath功能

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

細胞內創建一個功能

func showPopupPage(sender: UIButton) { 
    let view = button.superview! 
    let cell = view.superview as! custom cell 
    // you can get cell contents here 

// call your popupview pass the value 
} 

示例=> Swift - UIPopoverController in iOS 8

+0

謝謝,它使我popover從我的viewController tableviewcell,但我希望它像這個鏈接中的圖片: http://gracefullycoded.com/wp-content/uploads/2014/10/[email protected] 而不是我想添加mapview的文本和標籤 – RGB

+0

要在這裏添加mapView就是這個例子.http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial –

+0

仍然有同樣的問題。我不能從自定義單元格中的按鈕在tableview中彈出 – RGB

相關問題