ios - is this a retain cycle in Objective C? -
i've declared property on uicollectionviewcell this:
@property (nonatomic, copy) void(^onselection)(bool selected);
i override -setselected:
this:
- (void)setselected:(bool)selected { [super setselected:selected]; if (self.onselection != null) { self.onselection(selected); } }
then in -cellforitematindexpath:
configure this
cell.onselection = ^(bool selected) { //the compiler telling me might retain cycle dont think so... cell.tintcolor = [uicolor redcolor]; };
is retain cycle?
thanks!
yes is. instead should use weak+strong combo.
__weak typeof(cell) weakcell = cell; cell.onselection = ^(bool selected) { __strong typeof(weakcell) strongcell = weakcell; //the compiler telling me might retain cycle dont think so... strongcell.tintcolor = [uicolor redcolor]; };
in particular case don't need block because can update cell in subclass inside of setselected:
or handle tableview:didselectrowatindexpath:
in table view controller.
Comments
Post a Comment