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.
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.
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.
moveRow(at:to:) Moves the row at a specified location to a destination location.
If you haven't implemented a delegate (see nduplessis), UITableView also offers:
- (NSIndexPath *)indexPathForSelectedRow
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