Reputation: 529
Is there a way i can tag each individual cell and have them performSegueWithIdentifier to different ViewController? Currently, the coding only let me got to one tableview (calc). If i can have each individual cell got to Casing Capacity VC, Open Hole Capacity VC, etc, that would be great.
class searchtechData : UITableViewController, UISearchBarDelegate, UISearchDisplayDelegate {
var calculations = [Formulas]()
var filteredFormulas = [Formulas]()
override func viewDidLoad() {
self.calculations = [Formulas(category:"Capacity", name:"Open Hole Capacity"),
Formulas(category:"Capacity", name:"Casing Capacity"),
Formulas(category:"Hard", name:"Multiple String Annular Capacity"),
self.tableView.reloadData()
}
Tableview
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
var forumulas : Formulas
if tableView == self.searchDisplayController!.searchResultsTableView {
forumulas = filteredFormulas[indexPath.row]
} else {
forumulas = calculations[indexPath.row]
}
cell.textLabel!.text = forumulas.name
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
return cell
}
Segue to calc
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("calc", sender: tableView)
}
Upvotes: 0
Views: 411
Reputation: 10286
If you want to perform segue based on Formulas then you must store segue identifier ins Formulas or name segues based on Formulas name. Then in didSelectRow for index path do the following:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var forumulas : Formulas
if tableView == self.searchDisplayController!.searchResultsTableView {
forumulas = filteredFormulas[indexPath.row]
} else {
forumulas = calculations[indexPath.row]
}
self.performSegueWithIdentifier(forumulas.name, sender: tableView)
}
Upvotes: 1