In iOS 4, I have a UIPopoverController that opens a UITableViewContr开发者_如何学编程oller with a long list of items (66). How do I programmatically scroll to a specific cell of the tableview?
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndex:1] atScrollPosition: UITableViewScrollPositionNone animated:NO];
You can use this method of UITableView
:
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
Parameters
indexPath: An index path that identifies a row in the table view by its row index and its section index.
scrollPosition: A constant that identifies a relative position in the receiving table view (top, middle, bottom) for row when scrolling concludes. See “Table View Scroll Position” a descriptions of valid constants.
animated: YES if you want to animate the change in position, NO if it should be immediate.
NSIndexPath * someRowAtIndexPath = [NSIndexPath indexPathForRow:3 inSection:4];
[tableView scrollToRowAtIndexPath:someRowAtIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
精彩评论