呼叫超级时访问错误
在从直接超类重写的函数中,当函数尝试调用自身的超类版本时,会抛出 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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果发现超级调用中存在赋值错误。我本来应该将一个新变量分配给参数的强制转换,但改为将其分配给它本身。当从子类实现调用时,这可以预见地崩溃了。如果直接调用,这实际上是作为参数的变量,即预期的行为。向函数添加日志语句或更改编译器标志会改变此行为,因此这似乎只是垃圾内存的侥幸。
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.