gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:20:37 34 4
gpt4 key购买 nike

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

此问题仅在 theTableView.bounces = NO; 时发生,否则,它会完美运行。

我通过实现适当的委托(delegate)方法验证了这一点。

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

-(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

我见过其他类似的问题,但他们都在另一个 ScrollView 中使用表格,这里不是这种情况。

有没有人找到解决办法或解决方法?我在 iOS 7.0 ... 8.2 上试过,但所有系统都存在问题。

谢谢!

最佳答案

经过多次测试,我发现问题发生在表格的 contentOffset.y 达到最大值或 0 时。所以我创建了自己的“弹跳效果”,但规模要小得多在 TableView 的委托(delegate)中实现 scrollViewWillEndDragging:withVelocity:targetContentOffset: 如下:

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

有了它,问题就消失了。这是一种解决方法,但效果很好!

关于ios - 在非弹跳的 UITableView 中滚动后,行选择在第一次点击时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29140580/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com