Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollToRowAtIndexPath with row 0 scrolls to header not row

Tags:

ios

I have this line

[self.tableView scrollToRowAtIndexPath:self.cellIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

The cellIndexPath is section 2, row 0.

Instead of scrolling to the row it scrolls to the header of section 2.

Testing shows this seems to be the default behavior. Is there any way to override it and actually scroll to row 0?

Thanks

like image 945
DarkAgeOutlaw Avatar asked Feb 26 '16 17:02

DarkAgeOutlaw


1 Answers

You could get the cell's rectangle and then scroll to that.

CGRect cellRect = [myTableView rectForRowAtIndexPath:cellIndexPath];
[myTableView setContentOffset:CGPointMake(0,(cellRect.origin.y)) animated:YES];
like image 198
Dancreek Avatar answered Nov 20 '22 09:11

Dancreek