调用委托方法,无法识别的选择器,因为发送到错误的对象 [英] Calling delegate method, unrecognized selector because sending to wrong object

查看:66
本文介绍了调用委托方法,无法识别的选择器,因为发送到错误的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我进行了大量网络加载.我的数据模型由"Loader"对象组成,这些对象进行此加载并在完成/失败时调用其委托.代表都符合"LoaderDelegate"协议.

In my app I do a lot of network loading. My data model consists of "Loader" objects that do this loading and call their delegate when finished/failed. The delegates all conform to a "LoaderDelegate" protocol.

我遇到的问题是,有时看似随机的对象而不是委托人正在获取委托消息.当然,这会由于选择器无法识别而导致崩溃.

The issue I'm having is that sometimes seemingly random objects, not the delegate, are getting the delegate messages. This of course causes a crash because of an unrecognized selector.

只有一组崩溃日志告诉我,哪个装载机有问题,而其他装载机则没有该信息,只是获得消息的随机对象.

Only one set of crash logs tell me which one of my loaders is having the issue, the others don't have that information, just the random object that got the message.

我坚持如何确定此问题的真正原因.

I'm stuck at how to determine the real cause of this issue.

一组崩溃日志中有一个加载器试图调用它的委托但到达_UIImageViewExtendedStorage.另一个具有装载程序的装载机正在到达__NSCFInputStream.另一个__NSBlockVariable__.还有另一个CALayer.

One set of crash logs has a loader trying to call it's delegate but reaching _UIImageViewExtendedStorage. Another has a loader is reaching __NSCFInputStream. Another __NSBlockVariable__. And yet another, CALayer.

那只是我三天前的最新Beta版.

And that's just in my latest beta from 3 days ago.

如果每次都是相同的对象,那将是一回事,但似乎几乎是随机的.内存是否可能以某种方式被新对象覆盖?

It would be one thing if it was the same object each time, but it seems almost random. Is it possible that memory is getting overritten with a new object somehow?

我所有装载程序的委托属性是一个assign属性,但是当装载程序完成时,委托始终处于活动状态(代理是我的视图控制器调用的装载程序).

My delegate property for all of my loaders is an assign property, but the delegate is always alive when the loader finishes (delegates are my view controllers calling the loaders).

推荐答案

结果是,我在各处随机出现此错误,只是不是在这个特定的类中,而不仅仅是委托方法.

Turns out I was getting this error randomly all over the place, just not in this particular class and not just with delegate methods.

在我的情况下,问题出在我正在多个线程中访问各种类的属性,而这些属性是非原子的.自从我修复了该问题(删除了属性的非原子属性)以来,我再也没有看到这种情况了.

In my case, the problem turned out to be that I was accessing properties of various classes in multiple threads and those properties were nonatomic. Since I fixed that (removed nonatomic attribute of the properties), I haven't seen this happen anymore.

这篇关于调用委托方法,无法识别的选择器,因为发送到错误的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆