gpt4 book ai didi

iphone - scrollToRowAtIndexPath 不滚动到非事件/卸载的单元格

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:13 27 4
gpt4 key购买 nike

我注意到 scrollToRowAtIndexPath: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];
}

最佳答案

好的,我知道了原因,你看,你有:

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

当您为 View 外的单元格发送 indexPathForCell: 时,它返回 nil,因此 tableView 不知道要滚动到哪里。

关于iphone - scrollToRowAtIndexPath 不滚动到非事件/卸载的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9926424/

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