ios - Table View (Inside View Controller) Segue Not Working -
i have table view embedded in view controller, , want able setup segues 4 other view controllers depending on cell in view controller clicked.
however, can't seem figure out how control+drag segue table view view controller.
i believe relevant section of code be:
import uikit class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate { let options = ["home", "my account", "settings", "support"] //mark: properties var selecteditem: string? @iboutlet weak var nametextfield: uilabel! @iboutlet weak var tableview: uitableview! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath indexpath) cell.textlabel?.text = options[indexpath.row] return cell } func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int { return options.count } //mark: actions func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) { if let selectedrow = tableview.cellforrow(at: indexpath){ selecteditem = selectedrow.textlabel?.text } if selecteditem == "my account"{ performsegue(withidentifier: "classifysegue", sender: self) } else if selecteditem == "settings"{ performsegue(withidentifier: "othersegue", sender: self) } } }
the problem current othersegue comes view controller , not table view itself.
it doesn't need come tableview itself. segue should come vc tableview contained.
your code still work since
performsegue(withidentifier: "classifysegue", sender: self)
is invoking perform segue self viewcontroller
note: in didselect function, don't need cell again, set selecteditem self.options[indexpath.row] since you're trying text pass in cell initially.
Comments
Post a Comment