我有一個對象Person
和協議PersonDelegate
Person
具有@property (assign) id<PersonDelegate> delegate
;目標C - 調用方法的dealloc上委託
的地方在我的代碼我做的:
Person *newPerson = [[Person alloc] init];
newPerson.delegate = theDelegate;
...
[theDelegate release]; // and dealloc
...
now Person has some new information for the delegate, so I call in Person
[self.delegate doSomething];
但後來我得到EXC_BAD_ACCESS
這是因爲委託已dealloc的?人怎麼知道他的代表是dealloc?
但通常代表被分配,它是如何工作的? – Eyal
很可能是因爲大多數代表都是視圖控制器或持續超過對象本身的對象。在這種情況下,他明確地立即釋放代表 – giorashc