Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView Detect Selected Cell?

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.

like image 292
Josh Kahane Avatar asked Nov 30 '10 20:11

Josh Kahane


People also ask

How do you get the IndexPath row when a button in a cell is tapped?

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.

What is Uitableview in Swift?

A view that presents data using rows in a single column.

How do I change the background color of a selected cell in Swift?

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.


2 Answers

Get currently selected index path for a table:

NSIndexPath *path = [tableView indexPathForSelectedRow];

Deselect currently selected row:

[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
like image 111
Jeremy Fuller Avatar answered Oct 20 '22 00:10

Jeremy Fuller


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

like image 40
David Liu Avatar answered Oct 19 '22 23:10

David Liu