滚动时禁用scrollPosition

时间:2014-07-09 20:09:41

标签: ios uitableview uiscrollview didselectrowatindexpath

我有一个程序使用scrollPosition = UITableViewScrollPositionTop在顶部显示所选行。但是当我向下滚动并单击任何其他行时,滚动条会滚动回到第一个选定的行。有什么办法可以在我滚动时禁用UIScrollPositionTop。或者其他任何解决方案吗?

在定期间隔后调用此方法以突出显示(选择)行。

-(void)highlightcell:(int *)rows {

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:*rows inSection:0]; 
[tableview selectRowAtIndexPath:indexPath animated:YES  scrollPosition:UITableViewScrollPositionTop];

}

2 个答案:

答案 0 :(得分:0)

您可以使用UIScrollView委托来检测滚动何时开始以及何时停止,然后使用标志来保持滚动状态如下:

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    isScrolling = YES;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    isScrolling = NO;
}

然后在你的方法中:

-(void)highlightcell:(int *)rows {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:*rows inSection:0]; 

if (isScrolling) {
    [tableview selectRowAtIndexPath:indexPath animated:YES     scrollPosition:UITableViewScrollPositionNone];
}
else {
    [tableview selectRowAtIndexPath:indexPath animated:YES     scrollPosition:UITableViewScrollPositionTop];
}

}

答案 1 :(得分:0)

尝试这样做..

    Self.Table_small.scrollEnabled=NO;
相关问题