Ios UITababVIEW在帧中间选择行

Ios UITababVIEW在帧中间选择行,ios,uitableview,uipickerview,Ios,Uitableview,Uipickerview,我需要有可能把选定的线的中间帧。因此,如果我选择第一行或最后一行,这一行需要在中间,而不是夹在tableview的顶部(或底部)(类似于UIPickerView) 这是我在ScrollViewWillendDraging上的代码: - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetC

我需要有可能把选定的线的中间帧。因此,如果我选择第一行或最后一行,这一行需要在中间,而不是夹在tableview的顶部(或底部)(类似于
UIPickerView

这是我在ScrollViewWillendDraging上的代码:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
                     withVelocity:(CGPoint)velocity
              targetContentOffset:(inout CGPoint *)targetContentOffset {

    CGFloat rowHeight = [delegate rowHeightForMyPickerView:self];
    CGFloat floatVal = targetContentOffset->y / rowHeight;
    NSInteger rounded = (NSInteger)(lround(floatVal));
    targetContentOffset->y = rounded * rowHeight;
    NSLog(@"Offset: %f Float: %f Row: %d",targetContentOffset->y,floatVal,rounded);
    [delegate myPickerView:self isOverRow:rounded];
}

使用此代码,我创建了捕捉效果,但
四舍五入
不是正确的行。将第一个和最后一个单元格高度更改为双倍高度会使问题消失,但我不喜欢这种解决方案。
UITableView
类可以使用
scrollToRowatinexPath:atScrollPosition:animated
方法滚动到所选的
indexPath
,并带有动画。最好在
tableView:didSelectRowAtIndexPath:indepath
方法中添加:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; //scrolls the selected cell to middle
}

不是我需要的,例如,如果我有3个可见行,我需要将第一行(索引=0)放在第二个位置,因此:一个空格,第0行,第1行与我需要的最后一行相同:最后一行,第1行,空格