【发布时间】:2012-07-27 09:26:45
【问题描述】:
我有下一个代码:
// create new delegate
MyCustomApplicationDelegate *redelegate = [[MyCustomApplicationDelegate alloc] init];
redelegate.delegate = [(NSObject<UIApplicationDelegate42> *)[UIApplication sharedApplication].delegate retain];
// replace delegate
[UIApplication sharedApplication].delegate = redelegate;
...
[UIApplication sharedApplication].delegate = redelegate.delegate;
[redelegate.delegate release];
在最后一行之后,系统调用了基础 UIApplicationDelegate 类的 dealloc 方法。 所以为什么?我阅读了有关 UIApplication 和委托属性的 Apple 文档:
@property(nonatomic, assign) id 委托
讨论delegate必须采用UIApplicationDelegate形式 协议。 UIApplication 分配但不保留委托。
它明确表示 UIApplication 分配而不保留委托。那么,为什么它会破坏我的基础委托?
【问题讨论】:
标签: ios