Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepareForReuse

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
like image 826
jdog Avatar asked Mar 02 '11 02:03

jdog


People also ask

What is prepareForReuse?

'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.

What is prepare to reuse Swift?

prepareForReuse()Prepares a reusable cell for reuse by the table view's delegate.

What is DequeueReusableCell?

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 .

Which of the following are functions of the Uitableviewdatasource protocol?

Providing cells, headers, and footers.


1 Answers

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.

like image 137
Daniel T. Avatar answered Sep 16 '22 12:09

Daniel T.