在非弹跳的 UITableView 中滚动后,行选择在第一次点击时不起作用
Row selection doesn't work on first tap after scroll in a non-bouncing UITableView
基本上我看到的问题似乎是 Apple 的错误。问题是在滚动 table 后,第一次点击任何行只会突出显示它。需要第二次点击才能真正 select 或去 select 它。我注意到这个问题大多数时候都会发生。很少几次它会按预期工作,但我没有注意到它何时工作的任何模式。
只有 theTableView.bounces = NO;
才会出现此问题,否则,它会完美运行。
我通过实施适当的委托方法验证了这一点。
滚动后首先点击任意行,我收到这些回调
-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
滚动后在同一行或不同行上的后续点击,我收到这些回调
-(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
我看过其他类似的问题,但他们都在另一个滚动视图中使用 table,这里不是这种情况。
有没有人找到解决办法或解决方法?我在 iOS 7.0 ... 8.2 上试过,但所有版本都存在问题。
谢谢!
经过多次测试,我发现问题发生在 table 的 contentOffset.y
达到最大值或 0 时。所以我创建了自己的 "bouncing effect" 但在通过在 table 视图的委托中实现 scrollViewWillEndDragging:withVelocity:targetContentOffset:
来缩小规模,如下所示:
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
targetContentOffset->y = MAX(targetContentOffset->y -1, 1);
}
有了这个,问题就消失了。这是一种解决方法,但效果很好!
Swift 的4种语法:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
targetContentOffset.pointee.y = max(targetContentOffset.pointee.y - 1, 1)
}
基本上我看到的问题似乎是 Apple 的错误。问题是在滚动 table 后,第一次点击任何行只会突出显示它。需要第二次点击才能真正 select 或去 select 它。我注意到这个问题大多数时候都会发生。很少几次它会按预期工作,但我没有注意到它何时工作的任何模式。
只有 theTableView.bounces = NO;
才会出现此问题,否则,它会完美运行。
我通过实施适当的委托方法验证了这一点。
滚动后首先点击任意行,我收到这些回调
-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath
滚动后在同一行或不同行上的后续点击,我收到这些回调
-(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
我看过其他类似的问题,但他们都在另一个滚动视图中使用 table,这里不是这种情况。
有没有人找到解决办法或解决方法?我在 iOS 7.0 ... 8.2 上试过,但所有版本都存在问题。
谢谢!
经过多次测试,我发现问题发生在 table 的 contentOffset.y
达到最大值或 0 时。所以我创建了自己的 "bouncing effect" 但在通过在 table 视图的委托中实现 scrollViewWillEndDragging:withVelocity:targetContentOffset:
来缩小规模,如下所示:
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
targetContentOffset->y = MAX(targetContentOffset->y -1, 1);
}
有了这个,问题就消失了。这是一种解决方法,但效果很好!
Swift
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
targetContentOffset.pointee.y = max(targetContentOffset.pointee.y - 1, 1)
}