iphone - 将对象的委托(delegate)设置为 nil,这些对象在 cellforrowatindexpath 中分配给 self

标签 iphone ios uitableview delegates

我的应用程序中有一个自定义控件,例如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/

相关文章:

ios - xcode、macbook 和复制缓冲区插入 iPhone?

ios - 铛 : error: no such file or directory: ASIAuthenticationDialog. 米

ios - Objective-C Game Center自动匹配“由于与服务器通信出错,无法完成请求的操作。”

ios - iOS中的跳过/忽略方法

ios - PFQueryTableViewController 错误

iphone - 来自文本的 CGPathRef

iphone - NSString 值一旦提供值就不能更改吗?

ios - Xcode 可执行文件使用无效权利签名

iphone - 链接到框架是什么意思? (iOS)

ios - 在 Swift 中加载其他元素后,在 TableViewCell 中异步加载一个元素