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.
+1
A:
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];
}
Ed Marty
2010-04-14 22:10:48
wow, setContentOffset really saves the day, thanks!
Mike
2010-04-14 22:29:12