Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - what row was selected?

I have a question - how can I get a number of row selected in a table? I am assigning it manually to a variable. The problem is that if a row was deselected, my variable still keeps the old value.

What can I do about it? Is there a method in UITableView that returns a number of a currently selected row?

Thank you in advance, Ilya.

like image 230
Ilya Suzdalnitski Avatar asked Mar 19 '09 20:03

Ilya Suzdalnitski


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 indexPath row Swift?

In Swift, an indexPath is a list of indexes that, together, represent the path to a specific location in a tree of nested arrays. It describes an item's position inside a table view or collection view, storing both its section and its position inside that section.

Which method is used to allow moving of row in UITableView?

moveRow(at:to:) Moves the row at a specified location to a destination location.


1 Answers

If you haven't implemented a delegate (see nduplessis), UITableView also offers:

- (NSIndexPath *)indexPathForSelectedRow 
like image 140
Jarret Hardie Avatar answered Sep 17 '22 14:09

Jarret Hardie