Can someone please show me how to use prepareForReuse? I have been searching for hours and read dev docs.
In my custom cell, which extends UITableViewCell I have the prepareForReuse method and its getting called, but what do I do with it (having rendering issues). Do I do this deadline = @"" for each label?
@implementation PostTableCustomCellController
@synthesize authorName;
@synthesize deadline;
@synthesize distance;
@synthesize interestedCount;
@synthesize description;
@synthesize avatar;
@synthesize viewForBackground;
@synthesize fetchedResultsController, managedObjectContext;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void) prepareForReuse {
NSLog(@"prep for reuse");
[self clearFields];
}
- (void) clearFields {
NSLog(@"clearFields was called Jason");
}
- (void)dealloc {
[super dealloc];
}
@end
'Preparing for re-use' means checking, cleaning or repairing recovery operations, by which products or components of products that have become waste are prepared so that they can be re-used without any other pre-processing.
prepareForReuse()Prepares a reusable cell for reuse by the table view's delegate.
DequeueReusableCell(String) Returns a reusable table view cell that was created with the given ReuseIdentifier. DequeueReusableCell(NSString, NSIndexPath) Returns a reusable table view cell for the given reuseIdentifier , properly sized for the indexPath .
Providing cells, headers, and footers.
Once an object is constructed, calling the any of the init
methods is unacceptable, so there must be some way to reset the object back to a neutral state before it gets reused. That's what prepareForReuse
is for. You use that method to put the object back in the same state it was in right after the init
method was called so that the calling code will do the same thing, whether it is given a new object or a reused one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With