weird issue with UITableViewCell loading
I have a custom UITableViewCell and when I try to load the table, I got the following issue. Does anyone here know what is going on?
Here's some code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"FTPostCell";
FTPostCell *cell = (FTPostCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[FTPostCell alloc] initWithFrame:CGRectZero] autorelease];
}
//snips
}
- (id) initWithFrame: (CGRect)frame {
self = [super initWithFrame: frame];
开发者_运维技巧 if (self) {
self.like_img = [[[UIButton alloc] initWithFrame:CGRectMake(5, 75, 30, 30)] autorelease];
[self.like_img setImage:[UIImage imageNamed:@"favorite.png"] forState:UIControlStateNormal];
[self.contentView addSubview: self.like_img];
self.number_like = [[UILabel alloc] initWithFrame:CGRectMake(15, 110, 20, 12)];
[self.contentView addSubview:self.number_like];
self.comment_img = [[[UIButton alloc] initWithFrame:CGRectMake(5, 120, 30, 30)] autorelease];
[self.comment_img setImage:[UIImage imageNamed:@"comment.png"] forState:UIControlStateNormal];
[self.contentView addSubview: self.comment_img];
self.number_comment = [[UILabel alloc] initWithFrame:CGRectMake(15, 155, 20, 12)];
[self.contentView addSubview:self.number_comment];
self.type_img = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 40, 30, 30)] autorelease];
[self.contentView addSubview:self.type_img];
self.avatar = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)] autorelease];
[self.contentView addSubview:self.avatar];
self.post_title= [[[UILabel alloc] initWithFrame:CGRectMake(50, 30, 700, 50)] autorelease];
[self.contentView addSubview:self.post_title];
self.post_detail = [[[UILabel alloc] initWithFrame:CGRectMake(50, 10, 700, 10)] autorelease];
[self.contentView addSubview:self.post_detail];
self.post = [[[DTAttributedTextView alloc] initWithFrame:CGRectMake(50, 60, 600, 500)] autorelease];
self.post.textDelegate = self;
[self.contentView addSubview:self.post];
//self.postView = [[[DTAttributedTextContentView alloc] initWithFrame:CGRectMake(50, 60, 600, 500)] autorelease];
//[self.contentView addSubview:self.postView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lazyImageDidFinishLoading:) name:@"DTLazyImageViewDidFinishLoading" object:nil];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
[self.post_title sizeToFit];
[self.post_detail sizeToFit];
[self.post_detail setFont:[UIFont fontWithName:@"ArialMT" size:12.0]];
[self.post_title setFont:[UIFont fontWithName:@"Arial-BoldMT" size:18.0]];
[self.number_comment setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14.0]];
[self.number_like setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14.0]];
[self.number_like setTextColor:[UIColor grayColor]];
[self.number_comment setTextColor:[UIColor grayColor]];
[self.post_title setTextColor:[UIColor blueColor]];
}
That happens if you reuse table cells but don't properly reset them. Generally for rich text cells you might want to not reuse cells if the overhead in layouting and rendering a new cell is less than resetting a cell.
精彩评论