Always show from the first index of a table?

I have a UITableView in one of my views. tableView say tableView has 100 indexes. If I scroll down and select the 50th index, clicking on another view.

So what I want, if I return to the tableView from the second view, the tableView should show from the first index. But currently it was in the index where I selected earlier. Please refer to the image below for a better understanding.

enter image description here

Here, smart is the 25th index. If I choose smart, he is pushed to a different look (detailed view). Therefore, if I return to this View table again, the table should reset and display at a glance. can i achieve this? I tried reloading the table and it does not work.

Please offer your ideas.

Thanks!!!

+3
ios iphone uitableview reloaddata
source share
5 answers

Try something like this:

 - (void)viewWillAppear:(BOOL)animated { [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; } 
+4
source share

Use this to display the first index in a tableview .

  NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:1 inSection:0]; [self.tbl_presentation selectRowAtIndexPath:myIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 

I hope this code is helpful to you.

+3
source share

You need to ask the table view to scroll to the first row using scrollToRowAtIndexPath:atScrollPosition:animated: using the scroll position of UITableViewScrollPositionTop . You can do this after a delay, depending on what other animations you continue.

+2
source share

Do something in viewWillAppear , as it will be called when u come back .

 - (void)viewWillAppear:(BOOL)animated { [yourTableView.scrollView setContentOffset:CGPointMake(0,0)]; } 
+2
source share

Save the row index or value before moving to another view that you want to save, and show it in plain sight.

After that, when you return to the same view, just add the following line:

 // rowIndex is saved row value before navigating to another view. [tableView selectRowAtIndexPath:rowIndex animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 

This will solve your problem.

+1
source share

All Articles