0
我是一個UITableView設置並加載了大約3條記錄。 Interface Builder中UITableView的高度僅爲44像素。每行的高度設置爲44像素。爲什麼我的UITableView不能滾動到正確的索引行?
這意味着一次只能看到一行,但可以拖動並滾動到新行。我想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];
}
我的問題是,無論我做什麼,它總是滾動回於1行的記錄。我可以一直拖到第三排,然後放手,並一直滾動回到第一條記錄?如果在我放手之後它是最顯眼的行,它不應該滾動並居中第3行嗎?
謝謝!