我的应用程序中有一个自定义控件,例如CustomControl
。我在 View Controller 的 TableView 中使用的每个自定义 UITableViewCell
中都使用了此控件。
在某些事件中,我想将 CustomControl 的状态通知给 View Controller 。因此,我为 CustomControl 创建了协议(protocol),并且我希望 View Controller 通知,因此我在我的 cellForRowAtIndexPath
中分配了 customCell.customControl.delegate = self;
。
现在我想将 View Controller 的 dealloc
中的所有自定义单元格的委托(delegate)设置为 nil。谁能告诉我该怎么做?
最佳答案
假设您总是在 cellForRowAtIndexPath
方法中设置自定义控件的委托(delegate),您可以在 CustomCell 类中尝试这样的事情:
- (void)prepareForReuse
{
[super prepareForReuse];
self.myCustomControl.delegate = nil;
}
关于iphone - 将对象的委托(delegate)设置为 nil,这些对象在 cellforrowatindexpath 中分配给 self,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19298104/