Iphone 从其他线程滚动到RowatineXpath

Iphone 从其他线程滚动到RowatineXpath,iphone,Iphone,我正在尝试在tableView上使用ScrollToRowatineXpath。 我正在使用下面的方法 当我通过单击UIBarButtonItem调用此方法时,一切都正常,这意味着tableView可以正常滚动。但是,当我从另一个线程调用这个方法时,它不会滚动 想法 -(void)handleDiffView { NSIndexPath * ndxPath; if ( !isLooking ) { ndxPath= [NSIndexPath indexPathF

我正在尝试在tableView上使用ScrollToRowatineXpath。 我正在使用下面的方法

当我通过单击UIBarButtonItem调用此方法时,一切都正常,这意味着tableView可以正常滚动。但是,当我从另一个线程调用这个方法时,它不会滚动

想法

-(void)handleDiffView
{
    NSIndexPath * ndxPath;

    if ( !isLooking ) {
        ndxPath= [NSIndexPath indexPathForRow:1 inSection:0];
    }
    else {
        ndxPath= [NSIndexPath indexPathForRow:0 inSection:0];
    }


    [self.tableView scrollToRowAtIndexPath:ndxPath atScrollPosition:UITableViewScrollPositionTop  animated:YES];

}
发件人:

重要提示:UIKit类通常不是线程安全的。所有与绘图相关的操作都应在应用程序的主线程上执行


您可以使用调用主线程上的方法。

我想您可以通过调用
-[NSObject performSelectorOnMainThread:withObject:waitUntilDone:
来实现,如下所示:

// This will only be called from handleDiffView
- (void)handleDiffViewInMainThread:(NSIndexPath*)ndxPath
{
    [self.tableView scrollToRowAtIndexPath:ndxPath
                          atScrollPosition:UITableViewScrollPositionTop
                                  animated:YES];
}

- (void)handleDiffView {
    NSIndexPath * ndxPath;

    if ( !isLooking ) {
        ndxPath= [NSIndexPath indexPathForRow:1 inSection:0];
    }
    else {
        ndxPath= [NSIndexPath indexPathForRow:0 inSection:0];
    }

    [self performSelectorOnMainThread:@selector(handleDiffViewInMainThread:)
        withObject:ndxPath waitUntilDone:NO];
}