0
我一直在使用類別添加副本屬性的UITableViewCell如下圖所示如何在目標C中使用類別添加複製屬性?
NSString const *key = @"CellSelectedBlockKey";
@interface UITableViewCell (CellSelectionBlock)
@property (nonatomic, copy) CellSelectedBlock cellSelectedBlock;
@end
@implementation UITableViewCell (CellSelectionBlock)
- (void)setCellSelectedBlock:(void(^)(UITableView *table, NSIndexPath *indexpath))cellSelectedBlock
{
objc_setAssociatedObject(self, &key, cellSelectedBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (CellSelectedBlock)cellSelectedBlock
{
return objc_getAssociatedObject(self, &key);
}
@end
我將如何清除內存(釋放),這個屬性,我可以爲這個不overite dealloc方法。
我會很感激任何幫助。任何有關將屬性添加到現有類而無需子類的最佳方法的建議。