prepareForReuse [英] prepareForReuse

查看:109
本文介绍了prepareForReuse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can someone please show me how to use prepareForReuse? I have been searching for hours and read dev docs.

在我的自定义单元格中,它扩展了UITableViewCell我有prepareForReuse方法并且它被调用,但我该怎么办它(有渲染问题)。我为每个标签做这个
截止日期= @吗?

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


推荐答案

一旦构造了一个对象,调用任何 init 方法是不可接受的,所以必须有某种方法将对象重置回一个中性状态在被重用之前。这就是 prepareForReuse 的用途。在调用 init 方法后,使用该方法将对象恢复到原来的状态,这样调用代码将执行相同的操作,无论是给定一个新对象或一个重用对象。

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.

这篇关于prepareForReuse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆