简体   繁体   中英

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM