从 Apple 示例“PageControl”中我们可以知道 UIPageControl 可用于控制滚动视图中页面的移动。
由于 UITableView 是 UIScrollView 的子类,我想使用 UIPageControl 来控制表格视图单元格的移动,就像在“PageControl”中一样。
但是找不到任何委托接口让我这样做。
问题是:
有可能做到这一点吗?为什么?
谢谢
让我回答我的问题:
以编程方式选择和滚动
清单 6-5 以编程方式选择一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {
NSIndexPath *scrollIndexPath;
if (newIndexPath.row + 20 < [timeZoneNames count]) {
scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row+20 inSection:newIndexPath.section];
} else {
scrollIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row-20 inSection:newIndexPath.section];
}
[theTableView selectRowAtIndexPath:scrollIndexPath animated:YES
scrollPosition:UITableViewScrollPositionMiddle];
}