呼叫超级时访问错误

发布于 2024-12-13 11:48:25 字数 414 浏览 2 评论 0 原文

在从直接超类重写的函数中,当函数尝试调用自身的超类版本时,会抛出 exc_bad_access 。执行不会进入超类的函数,而是抛出来自 objc_msgSend 的信号。类和两个参数均符合预期。如果 expired 为 true,则调用不会失败,在其他地方调用超类函数也不会失败。

- (void)customizeCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    if (expired)
    {
        //do some things
    }
    else
    {
        //fails here
        [super customizeCell:cell atIndexPath:indexPath];
    }
}

In a function overridden from the immediate superclass, an exc_bad_access is being thrown when the function tries to call the superclass version of itself. The execution does not make it into the superclass' function, but instead throws the signal from objc_msgSend. The class and both parameters are as expected. The call does not fail if expired is true, nor does the superclass function fail when called elsewhere.

- (void)customizeCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    if (expired)
    {
        //do some things
    }
    else
    {
        //fails here
        [super customizeCell:cell atIndexPath:indexPath];
    }
}

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

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

发布评论

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

评论(1

倥絔 2024-12-20 11:48:25

结果发现超级调用中存在赋值错误。我本来应该将一个新变量分配给参数的强制转换,但改为将其分配给它本身。当从子类实现调用时,这可以预见地崩溃了。如果直接调用,这实际上是作为参数的变量,即预期的行为。向函数添加日志语句或更改编译器标志会改变此行为,因此这似乎只是垃圾内存的侥幸。

Turns out there was an assignment error in the supercall. I was supposed to be assigning a new variable to a cast of a parameter, but instead assigned it be itself. This predictably crashed when called from the subclass implementation. If called directly, this actually the variable to be the parameter, the intended behaviour. Adding logging statements to the function or changing the compiler flags change this behaviour, so it seems that this was just a fluke with garbage memory.

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