为什么保留委托是错误的,所有替代方案是什么......?
我有一个问题,假设A和B是2个视图控制器,从A用户推送到B视图控制器,在B中,用户通过创建对象C(它是NSObject类)开始一些下载,并将B设置为C的委托(分配),现在用户想要返回到 A,然后释放 B 调用对象释放,C 委托无法回拨(崩溃)。我想要获得呼叫并允许用户移动到其他视图控制器,这就是我在 C 类中保留委托的方式,但是保留代表是错误的......
what are all solutions ...
提前致谢。
I have one problem let assume A and B are 2 view controller from A user push to B view controller,In B user starts some download by creating object C(which is NSObject class) and sets B as delegate to C(assign),now user want go back to A then dealloc of B calls object releases, C delegate fails to give call back(crashes).I want to get call and allow user to move to other view controller thats way i am retain the delegate in C class but retain of delegate is wrong ...
what are all solutions ...
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我看到两个选项:
I see two options:
发生这种情况是因为您的架构中存在问题:您将后台下载的全局任务分配给可能位于内存中也可能不在内存中的视图控制器。
如果您希望无论 B 是否存在都能够继续下载,那么:
init
方法或@property
将 C 的实例注入 B 中。That happens because of an issue in your architecture: you're assigning the global task of background downloading to a view controller that may or may not be in memory.
If you want to be able to continue the download regardless of the presence of B, then:
NSNotification
instead of delegate so that multiple object can monitor at the same time.init
method or a@property
.