Iphone ScrollToRowatineXpath不滚动到非活动/卸载的单元格

Iphone ScrollToRowatineXpath不滚动到非活动/卸载的单元格,iphone,objective-c,xcode,ios5,Iphone,Objective C,Xcode,Ios5,我注意到,ScrollToRowatinedExath:atScrollPosition:animated:不会滚动到当前未显示的单元格,因此如果我有100个单元格,并且需要在70时到达该单元格,则对该选择器的调用将不会起任何作用 有没有办法让我把那个细胞记起来?我已经有了单元格的索引路径 当用户想要去那里时,我需要在我的应用程序中滚动到那个位置 谢谢你的任何想法 编辑:@dasblinkenlight - (void)viewDidLoad { [[NSNotificationCent

我注意到,
ScrollToRowatinedExath:atScrollPosition:animated:
不会滚动到当前未显示的单元格,因此如果我有100个单元格,并且需要在70时到达该单元格,则对该选择器的调用将不会起任何作用

有没有办法让我把那个细胞记起来?我已经有了单元格的索引路径

当用户想要去那里时,我需要在我的应用程序中滚动到那个位置

谢谢你的任何想法

编辑:@dasblinkenlight

- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillHide
{
    //Load remote cell here then scroll
    // :( dont know how to load remote cell yet
}

- (void)keyboardWillShow
{
    //Load remote cell here then scroll
    // :( dont know how to load remote cell yet
    //_cellIndexPath gets assigned on didSelectRowAtIndexPath:
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_cellIndexPath.row inSection:_cellIndexPath.section] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
编辑2:

- (void)keyboardWillShow
{
//Load remote cell here then scroll
    [NSThread detachNewThreadSelector:@selector(keyboardWillShowThreaded) toTarget:self withObject:nil];
}

- (void)keyboardWillShowThreaded
{
    [NSThread sleepForTimeInterval:2.0];
    [self performSelectorOnMainThread:@selector(keyboardWillShowMainThread) withObject:nil waitUntilDone:YES];
}

- (void)keyboardWillShowMainThread
{
    //Get the cell
    //_textFieldThatHasFirstResponder is a subview in the cell
    //This returns null, probably because the cell is not loaded into memory
    UITableViewCell *cell = [_textFieldThatHasFirstResponder superview];
    NSLog(@"CELL TO SCROLL TO: %@",cell);
    NSIndexPath *indexPathForCell = [self.tableView indexPathForCell:cell];
    [self.tableView scrollToRowAtIndexPath:indexPathForCell atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}

您可以实现一个委托,这样就可以从您所在的类中调用它,这样就可以更新位置

“我注意到
ScrollToRowatineXpath:atScrollPosition:animated:
不会滚动到当前未显示的单元格,因此如果 100个牢房,我要在70号找到那个 选择器将什么也不做。”

不,这不是真的。我刚刚尝试使用100行的tableview。下面的代码运行良好

 [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:78 inSection:0]
                     atScrollPosition:UITableViewScrollPositionNone animated:YES];

我不认为增加睡眠改变了什么。它只是延迟执行,但不影响订单。您能检查传递给ScrollToRowatineXpath的索引是否有效吗?我记得我自己也看到过同样的问题,但它与隐形细胞有关。无法检索不可见单元格(tableView返回nil),因此其索引路径为nil,因此滚动失败。 您可以存储所有单元格的位置,或者动态计算,然后将其传递给

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated;

这是我能想到的唯一解决办法。

好的,我已经找到了原因,看,你已经:

NSIndexPath *indexPathForCell = [self.tableView indexPathForCell:cell]; // nil here
[self.tableView scrollToRowAtIndexPath:indexPathForCell atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

当您发送
indexPathForCell:
时,对于看不见的单元格,它返回nil,因此tableView不知道滚动到哪里。

它应该滚动到可见区域之外的单元格。你能告诉我你是怎么调用的吗?你是用什么方法调用的?是的,也许你是对的,但我有8个单元格可以看到,当我点击第二个单元格时,它会滚动,但当我点击部分看不见的第8个单元格时,注意到会发生什么,当然还有很多单元格,但不可见,看不见的部分也不要滚动。你能显示一下你调用的部分吗?@dasblinkenlight编辑了我的问题。我认为问题是由键盘动画和滚动动画结合造成的。也许尝试在键盘显示动画完成后执行滚动(即:将滚动代码放在单独的方法中,并通过
-performSelector:afterDelay:
)调用它)我是从UITableView所在的类(即UITableView的委托类)调用它的,我现在也没有得到它,滚动仅适用于tableview上的前5个单元格。。。我尝试了所有不同的UITableViewScroll位置。如果我点击6+数字单元格,键盘就在它前面。也许你的加载时间有问题。请看我的作品中的EDIT2,更改了代码以包含一些时间。还是没什么