How to change selected cell of UITableViewController when returning to table view?

When you select a cell and go to the detailed view and return to the table view by touching the back button , the background color of the cell you selected is highlighted for the last time.

How can I select another cell that was not selected before returning to the table view from the detailed view?

For example, in the case of the Apple Music application, when you select and play a song and change a song by pressing next track button and return to the song table view, the highlighted cell is not the last song you listened to, but the song you last selected in table view.
But I want to highlight the song that you listened to last time.

Is it possible?

0
source share
3 answers

In the method that appears, you must undo the previous selection using the function below.

- deselectRowAtIndexPath: animated:

And after that, to select you need to call the method below. A message will appear

- selectRowAtIndexPath: animated: scrollPosition:

+1
source

You need to save the memory of NSIndexPath when the didSelectRow function is called.

In the viewWillAppear method, you must select a row for this saved index path using this method.

 - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition; 
+2
source

Before asking a question, read the documents . You will find:

 - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition 
0
source

All Articles