ios - How to perform a segue view from custom UITableViewCell(xib) to another ViewController -
i want show button on custom uitableviewcell takes user screen on tapping on it. have tried following code doesn't work
child view:
@ibaction func childscreenbutton(sender: anyobject) { if let delegate = self.delegate { delegate.childbuttonclickedoncell(self) } } protocol:
protocol childtablecelldelegate: class { func childbuttonclickedoncell(cell: childviewcell) } parent viewcontroller:
func childbuttonclickedoncell(cell: feedchildviewcell) { self.clickedindexpath = self.feedstableview.indexpathforcell(cell) self.performseguewithidentifier("tonextscreen", sender: self) } while i'm testing break point doesn't enter "delegate.childbuttonclickedoncell(self)" on child view. please let me know if doing wrong here. thanks!!
i suspect you've got couple things out of place, or not defined right.
i ran quick test this, , delegate call works fine... see if notice not-quite-the-same...
// // testtableviewcontroller.swift // // created donmag on 4/7/17. // copyright © 2017 donmag. rights reserved. // import uikit protocol mycelldelegate { func pressedbuttonformycell(thesender: mycell) } class mycell: uitableviewcell { @iboutlet weak var thelabel: uilabel! @iboutlet weak var thebutton: uibutton! var delegate: mycelldelegate? @ibaction func childscreenbutton(sender: anyobject) { delegate?.pressedbuttonformycell(thesender: self) } } class testtableviewcontroller: uitableviewcontroller, mycelldelegate { override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } // mark: - table view data source override func numberofsections(in tableview: uitableview) -> int { return 1 } override func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return 10 } override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "mycell", for: indexpath) as! mycell cell.thelabel.text = "\(indexpath)" cell.delegate = self return cell } func pressedbuttonformycell(thesender: mycell) { print("delegate called", thesender) } }
Comments
Post a Comment