UITableView scrolling for very large cells
I have UITableView with very large cells with lots of content (more than one screen height). I need to scroll UITableView to a certain position within those cells. I've found method scrollToRowAtIndexPath:atScrollPosition:animated: which works just fine if you got small cells (less than one screen), then you can just command UITableView to scroll, so the needed cell appears at the top of the screen (for example). 开发者_开发百科But this doesn't help at all when you got very large cells. I need UITableView to scroll to a certain position within my large cell, something like scrollToRowAtIndexPath but what accepts pixel offset in addition to cell number. Someone got any ideas? Or maybe ready solution... Would appreciate any help.
Since UITableView
is a subclass of UIScrollView
, you can use scroll view methods on the table. Specifically, setContentOffset:animated:
.
- (void) scrollToRowAtIndexPath:(NSIndexPath *)indexPath offset:(CGFloat)offset animated:(BOOL)animated {
CGRect rowFrame = [self.tableView rectForRowAtIndexPath:indexPath];
CGPoint origin = rowFrame.origin;
origin.y += offset;
[self.tableView setContentOffset:origin animated:animated];
}
精彩评论