gpt4 book ai didi

iphone - scrollToRowAtIndexPath 在设置我的 tableview 之前检查索引路径

转载 作者:行者123 更新时间:2023-11-28 19:22:09 28 4
gpt4 key购买 nike

我正在使用 scrollToRowAtIndexPath 将我的 tableview 集中在先前选择的单元格上,但是它在手机上而不是在模拟器上测试时崩溃了应用程序。

我是这样设置的

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//Center previously selected cell to center of the screen
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
}

这是它给出的错误

 *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (0) beyond bounds (0).'
*** First throw call stack:
(0x31fe88bf 0x31d581e5 0x31fe87b9 0x31fe87db 0x32b6df1f 0x29bef 0x32ae26b5 0x32b3daf1 0x32afed21 0x32afea71 0x32afe78b 0x32afe4ff 0x32ab581b 0x32abafb9 0x3193aba7 0x3273be8d 0x31fbb2dd 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34f5 0x2f70)
terminate called throwing an exception(gdb)

事情是我设定的

[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];

在另一种方法中,应用程序可以正常工作,但不会滚动到索引位置。我不知道如何修复它。

尝试延迟 scrollToRowAtIndexPath 时更新新错误

2011-11-02 16:00:58.180 code[2303:707] -[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410
2011-11-02 16:00:58.184 code[2303:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410'
*** First throw call stack:
(0x31fe88bf 0x31d581e5 0x31febacb 0x31fea945 0x31f45680 0x35bef943 0x31fbca63 0x31fbc6c9 0x31fbb29f 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34a9 0x2f24)
terminate called throwing an exception(gdb)

最佳答案

您可能不需要重新加载数据 - 只需在延迟后运行您的 scrollToRowAtIndexPath:

[self performSelector:@selector(methodThatCallsScrollToRow) withObject:nil afterDelay:2.5];

让表格有机会加载。

关于iphone - scrollToRowAtIndexPath 在设置我的 tableview 之前检查索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7975163/

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