Iphone 我想滚动到表格视图中的一行,选择单元格,然后取消选择它,但在我看到它之前,它已被取消选择

Iphone 我想滚动到表格视图中的一行,选择单元格,然后取消选择它,但在我看到它之前,它已被取消选择,iphone,uitableview,Iphone,Uitableview,我使用下面的代码 [sampleListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; [sampleListTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];

我使用下面的代码

    [sampleListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    [sampleListTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [sampleListTableView deselectRowAtIndexPath:indexPath animated:YES];
我正在寻找的行为是,表视图将滚动到路径(它确实如此) 然后立即选择该单元格(如果该单元格在屏幕上,则选择该单元格)

我认为滚动动画是线程化的,单元格在出现在屏幕上之前就被选中了,这在某种程度上得到了确认,就像我用屏幕上的单元格调用此代码时,它选择了,然后取消了选择一样

有人有解决办法吗?我可以这样做(没有滚动动画),但它没有那么甜蜜,事实上非常突然

    [sampleListTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
    [sampleListTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [sampleListTableView deselectRowAtIndexPath:indexPath animated:YES];

我不确定,但您可以尝试实现UIScrollViewDelegate协议的一些委托方法。是这样吗


然后在那里取消选择

以下是我的一个项目的代码:

#define kHighlightTableRowDuration  0.5

- (void)scrollToLastInsertedItem:(NSIndexPath *)indexPath
{

    @try
    {

        [myTableView scrollToRowAtIndexPath:indexPath
                       atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        if( rows >= 8 )
            [myTableView performSelector:@selector(flashRowAtIndexPath:) withObject:indexPath afterDelay:0.5];

    }
    @catch(NSException *ex) // NSRangeException
    {
        ALog(@"NSRangeException: %@",ex);
    }

}

// briefly highlight the last added item
- (void)flashRowAtIndexPath:(NSIndexPath *)indexPath
{

    // if cell is offscreen, nil returned
    UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];
    if( cell ){
        BOOL shouldHighlight = YES;

        if( ! cell.highlighted ){
            DLog(@"Starting cell highlight, setting on: %@", indexPath);
            shouldHighlight = YES;
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            [self performSelector:@selector(flashRowAtIndexPath:) withObject:indexPath afterDelay:kHighlightTableRowDuration];
        }else{
            DLog(@"Ending cell highlight, setting off: %@", indexPath);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            shouldHighlight = NO;
        }
        [cell setHighlighted:shouldHighlight animated:YES];
    }


}

flashRowAtIndexPath
被调用两次,第一次打开高亮显示,然后在给定延迟后再次关闭高亮显示。在我的
UITableView
中,选择样式通常为“无”,因此我必须更改选择样式以实现高亮显示。

很漂亮,这正是我所需要的,有太多的代理,你很难跟踪它们。
#define kHighlightTableRowDuration  0.5

- (void)scrollToLastInsertedItem:(NSIndexPath *)indexPath
{

    @try
    {

        [myTableView scrollToRowAtIndexPath:indexPath
                       atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        if( rows >= 8 )
            [myTableView performSelector:@selector(flashRowAtIndexPath:) withObject:indexPath afterDelay:0.5];

    }
    @catch(NSException *ex) // NSRangeException
    {
        ALog(@"NSRangeException: %@",ex);
    }

}

// briefly highlight the last added item
- (void)flashRowAtIndexPath:(NSIndexPath *)indexPath
{

    // if cell is offscreen, nil returned
    UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];
    if( cell ){
        BOOL shouldHighlight = YES;

        if( ! cell.highlighted ){
            DLog(@"Starting cell highlight, setting on: %@", indexPath);
            shouldHighlight = YES;
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            [self performSelector:@selector(flashRowAtIndexPath:) withObject:indexPath afterDelay:kHighlightTableRowDuration];
        }else{
            DLog(@"Ending cell highlight, setting off: %@", indexPath);
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            shouldHighlight = NO;
        }
        [cell setHighlighted:shouldHighlight animated:YES];
    }


}