CustomCell Dealloc in iPhone
When we create Custom Cell and use it to dequeueReusableCellWithIdentifier method, Whether we can dealloc its objects? Will it m开发者_运维问答ake any issue?
I'm sure you mean -release rather than -dealloc -- you should never send -dealloc to any object yourself, of course.
If you've got a custom UITableViewCell subclass, the right thing to do is to let the cell manage it's own instance variables or properties. So your cell class might look like:
@interface MyCustomCell : UITableViewCell
{
}
@property(copy, nonatomic) NSString *cellData;
@end
Then, in your table delegate's -tableView:cellForRowAtIndexPath: method, when you get one of your cells back from -dequeueReusableCellWithIdentifier:, you can just say:
cell.cellData = nil;
to prepare your cell for its next use. Setting the cellData property to nil will cause the property's setter to release its old string. This isn't strictly necessary if you're just going to set the cellData property to some other string anyway, but I think it's good practice to set a cell back to a known, empty state before you set it up for its new row. Another way to do that is to implement -prepareForReuse in the cell subclass.
精彩评论