I have multiple UITableViews in my app, is there a method of detecting which cell/row the user has selected in that column?
Also is it possible to programatically deselect a cell/row?
Thanks.
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
A view that presents data using rows in a single column.
Swift 3, 4, 5 select cell background colour Show activity on this post. Next connect your cell's selectedBackgroundView Outlet to this view. You can even connect multiple cells' outlets to this one view. Save this answer.
Get currently selected index path for a table:
NSIndexPath *path = [tableView indexPathForSelectedRow];
Deselect currently selected row:
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
These are all easily found in the documentation for UITableView. Perhaps you should look there first next time.
Here's even a link: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With