Reputation: 1
Im currently trying to send some information from custom cells to the next view controller in Xcode 7 with Swift 2.
I can send information fine if it is from a label etc but i cannot do it from cells as I'm unable to get the specific cell the user tapped. I have tried to take information from tutortials on how to get the index path but always get an error.
Any ideas on how to fix this?
Upvotes: 0
Views: 290
Reputation: 3310
ViewController
to ExpanView
Make sure
not for UITableViewCell
To ExpanView
tableView.allowsSelection = true
And set tableView.delegate = self
Implyment didSelectRowAtIndexPath
Method of tableView like this way.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("exapanView", sender: indexPath)
}
implement prepareForSegue
method like this way
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "exapanView" {
let selectedIndexPath = sender as! NSIndexPath
let nameString = self.name.objectAtIndex(selectedIndexPath.row)
}
}
Upvotes: 2