just wondering how I would go about implementing didSelectRowAtIndexPath or something similar into my app. I have a populated Table View with several dynamic cells and basi
This is how I managed to segue from UITableView cells to other view controllers after implementing cellForRow, numberOfRowsInSection & numberOfSectionsInTable.
//to grab a row, update your did select row at index path method to:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
NSLog("You selected cell number: \(indexPath.row)!");
if indexPath.row == 1 {
//THE SEGUE
self.performSegue(withIdentifier: "goToMainUI", sender: self)
}
}
Will output: You selected cell number: \(indexPath.row)!
Remember to match the identifier of your segue in story board to the identifier in the function, e.g goToMainUI.
Use the following code to select cell at '0' index programmatically for collectionView.
self.collectionView.reloadData()
DispatchQueue.main.async {
self.collectionView(self.collectionView, didSelectItemAt: IndexPath(item: 0, section: 0))
}
You can use didSelectRowAtIndexPath in Swift.
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
NSLog("You selected cell number: \(indexPath.row)!")
self.performSegueWithIdentifier("yourIdentifier", sender: self)
}
For Swift 3 it's
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
NSLog("You selected cell number: \(indexPath.row)!")
self.performSegueWithIdentifier("yourIdentifier", sender: self)
}
Just make sure you implement the UITableViewDelegate.