iphone – scrollToRowAtIndexPath不滚动到非活动/卸载的单元格
发布时间:2020-12-14 17:21:24 所属栏目:百科 来源:网络整理
导读:我注意到scrollToRowAtIndexPath:atScrollPosition:animated:不会滚动到当前不在视图中的单元格,所以如果我有100个单元格并且我需要到70处的那个单元格,那么对该选择器的调用将什么都不做. 有没有办法让那个细胞进入记忆?我已经有了单元格的索引路径……
我注意到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]; } EDIT2: - (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]; 当您发送indexPathForCell时:对于视图外单元格,它返回nil,因此tableView不知道滚动到哪里. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |