【发布时间】:2011-03-26 23:39:06
【问题描述】:
我设置了一个 UITableView 并加载了大约 3 条记录。 Interface Builder 中 UITableView 的高度只有 44 像素。每行的高度设置为 44 像素。
这意味着一次只能看到一行,但可以拖动并滚动到新行。我希望 UITableView 也总是显示滚动到的最明显的行。
我已经设置了以下代码:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
// Get the center of the UITableView bounds
CGPoint tableViewCenter = self.activeTableView.center;
// Get the row that is currently occupying the center point in the UITableView
NSIndexPath *row = [self.activeTableView indexPathForRowAtPoint:CGPointMake(tableViewCenter.x, tableViewCenter.y)];
// Animate and scroll to this row making it the only visible row.
[self.activeTableView scrollToRowAtIndexPath:row atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
我的问题是,无论我做什么,它总是滚动回第一行记录。我可以一直拖到第 3 行然后放手,它会一直滚动到第 1 条记录?如果我放手后第三行是最明显的行,它不应该滚动并居中吗?
谢谢!
【问题讨论】:
标签: iphone cocoa-touch uitableview ios4 uiscrollview