2016-03-30 13 views
0

私はUITableViewCell内にボタンがあり、別のビューに続いて実行する必要があります。 どうすればいいですか?代わりに、(あなたも代表団でそれを行うことができますが)直接セル上のコードを有していると、あなたのコントローラに直接コードを追加し、ボタンにメソッドをバインドできUITableViewCell Swift内でSegueを実行する2

class CustomCell: UITableViewCell { 

    @IBAction func btnShowView(sender: AnyObject) { 
     performSegueWithIdentifier("seguePrincipalImagem") 
    } 

    override func awakeFromNib() { 
     super.awakeFromNib() 
    } 
}  

答えて

0

、このような何か:

  1. のtableViewでボタンを(持っているセルを作成する過程では、あなたのUIViewController

    func btnShowView(sender: AnyObject) { 
        self.performSegueWithIdentifier("segue_identifier",selder:nil) 
    } 
    
  2. にセグエを実行する関数を作成します:CEL lForRowAtIndexPath :):

    //Inside tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier",indexPath) as! YourCustomTableViewCell 
    cell.yourBtn.addTarget(self, action: "btnShowView", forControlEvents: .TouchUpInside) 
    //More code to configure cell... 
    return cell 
    

そして、それはそれです。

関連する問題