prepareForReuse

jdo*_*dog 7 iphone objective-c uitableview

有人可以告诉我如何使用prepareForReuse吗?我一直在寻找几个小时并阅读开发文档.

在我的自定义单元格中,它扩展了UITableViewCell我有prepareForReuse方法及其调用,但我该如何处理它(有渲染问题).我为每个标签做截止日期= @""吗?

@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
Run Code Online (Sandbox Code Playgroud)

Dan*_* T. 9

一旦构造了一个对象,调用任何一个init方法都是不可接受的,所以必须有一些方法可以在重用之前将对象重置回中性状态.这prepareForReuse是为了什么.您可以使用该方法将对象放回到init调用方法后的状态,以便调用代码执行相同的操作,无论是给定新对象还是重用对象.