在非弹跳UITableView中滚动后,在第一次点击时行选择不起作用

Ahm*_*med 3 objective-c uitableview uiscrollview ios

基本上我看到的问题似乎是一个Apple bug.问题是在滚动表格之后,任何行上的第一次点击只会突出显示它.需要第二次点击才能实际选择或取消选择它.我注意到这个问题大多数时间都会发生.它很少会按预期工作,但我没有注意到它何时起作用的模式.

只有在theTableView.bounces = NO;其他情况下才会出现此问题,它完美无缺.

我通过实现适当的委托方法来验证这一点.

滚动后首先点击任意一行,我得到这些回叫

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

滚动后在相同或不同的行上进行后续点击,我得到这些回调

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath

//then

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//or
-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)

我已经看到了其他类似的问题,但是所有这些问题都在另一个滚动视图中使用了一个表,这不是这里的情况.

有没有人为此找到修复或解决方法?我试过iOS 7.0 ... 8.2并且所有这些问题都存在.

谢谢!

Ahm*_*med 9

经过大量的测试后,我发现当表达contentOffset.y到最大值或0 时就会出现问题.所以我创建了自己的"弹跳效果",但是通过scrollViewWillEndDragging:withVelocity:targetContentOffset:在表视图的委托中实现,规模要小得多,如下所示:

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    targetContentOffset->y = MAX(targetContentOffset->y -1, 1);
}
Run Code Online (Sandbox Code Playgroud)

有了这个,问题就消失了.这是一种解决方法,但就像一个魅力!