NSRangeException 导致应用程序在手机上崩溃,但在模拟器上则不然

发布于 2024-12-13 08:02:40 字数 1334 浏览 1 评论 0原文

首先,我将向您展示我遇到的错误,然后我将尝试解释我正在做什么来得到这个错误等等,

2011-11-02 10:17:57.665 code[1327:707] *** 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 0x29c9b 0x32ae26b5 0x32b3daf1 0x32afed21 0x32afea71 0x32afe78b 0x32afe4ff 0x32ab581b 0x32abafb9 0x3193aba7 0x3273be8d 0x31fbb2dd 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x35a1 0x301c)
terminate called throwing an exception(gdb) 

这就是我正在做的事情来得到这个错误。 在此处输入图像描述

每当我第二次进入数据集为indexpath[0,1]的子视图时应用程序将抛出此错误。

这是发生错误的代码。 subview.m

- (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]; //happens on this line
}

这是该错误的输出。 在此处输入图像描述

我应该看什么..我真的不知道这有什么好处或坏处。 真正令人沮丧的是,如果我从主视图或任何其他视图进出 IndexPath [0,0],它工作正常,并且这个应用程序永远不会出现问题。

我希望有人可以帮助我,或者至少让我知道问题可能是什么或出在哪里。

First of all Im going to show you the error I am getting, then I will try to explain what I am doing to get this error etc

2011-11-02 10:17:57.665 code[1327:707] *** 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 0x29c9b 0x32ae26b5 0x32b3daf1 0x32afed21 0x32afea71 0x32afe78b 0x32afe4ff 0x32ab581b 0x32abafb9 0x3193aba7 0x3273be8d 0x31fbb2dd 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x35a1 0x301c)
terminate called throwing an exception(gdb) 

This is what I am doing to get this error.
enter image description here

Any time that I enter the subview with the dataset of indexpath[0,1] for the second time the app will throw this error.

This is the code where the error happen.
subview.m

- (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]; //happens on this line
}

and this is the output from that error.
enter image description here

What should I be looking at.. I dont really know whats good or bad from this.
Whats really frustrating is that if I go in and out of IndexPath [0,0] from the main view or any of the other ones it works fine and there is never a problem with this app..

I am hoping someone can help me, or at the very least give me an idea of what the problem might be or where.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2024-12-20 08:02:40

我在我的项目中遇到了类似的问题,我从数据源中删除对象,然后立即调用 [self.tableview reloadData];

我为解决问题所做的就是调用:

dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
                [self.tableView reloadData];
            });

这基本上调用 在下一个运行循环中重新加载数据。您可以使用performSelector:afterDelay 执行类似的操作。

所以我的建议是尝试调用:

dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
  [self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
}

注意:您实际上不需要指定延迟时间,这两种技术强制在下一个运行循环开始时调用该方法。

I had a similar problem in my project where I was deleting objects from my datasource and then immediately calling [self.tableview reloadData];

What I did to solve the issue was call:

dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
                [self.tableView reloadData];
            });

This basically calls reloadData in the next run loop. You can do a similar thing using performSelector:afterDelay.

So my suggestion is try calling:

dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
  [self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
}

Note: You don't need to actually have a delay time specified, these 2 techniques force the method to be called at the start of the next run loop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文