UITableView will not scroll to a specific position

[self.tableView setContentOffset:CGPointMake(0,48) animated:NO]; 

I have a UITableView that has a UIView in the title. My UITableView will not scroll to (0.48) if it is not animated: YES. I do not want him to revive.

Does anyone know what?

+1
source share
2 answers

To set the UIView for the section title, you use the function:

 - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 

I suspect that you are calling setContentOffset somewhere in viewWillAppear, but this function is being called later. And I think this overwrites your content .... not sure why this does not happen when animated - YES, but anyway just put your setContentOffset in this function like this:

 - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = nil; if (section == SEC_WITH_IMAGE_HEADER) { headerView = self.neededView; } [self.tableView setContentOffset:CGPointMake(0,48) animated:NO]; return headerView; } 

Worked for me, hope it will be for someone else.

+2
source

You can try a method called -scrollRectToVisible: animated .


I misunderstand your question. So what do you want is to initialize a table view with a y-coordinate offset of about 48 pixels?

This will cause the tableView to start with yPos 48.

 tableView.contentInset = UIEdgeInsetsMake(48, 0.0, 0.0, 0.0); 

Hope this helps you ....

+2
source

Source: https://habr.com/ru/post/1311032/


All Articles