在 TableView 中设置单元格时遇到问题...我使用图像视图和两个标签、一个标题和一个详细信息设置了表格视图。第一部分看起来不错,但滚动后,它不断地将所有标签堆叠在一起。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
NSLog(@"%@", articleDateString);
// cell.textLabel.text = entry.articleTitle;
// cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", articleDateString, entry.blogTitle];
UIFont *cellFont = [UIFont fontWithName:@"ArialRoundedMTBold" size:17];
//cell.textLabel.font = cellFont;
UIFont *cellFont2 = [UIFont fontWithName:@"ArialRoundedMTBold" size:12];
//cell.detailTextLabel.font = cellFont2;
UIImage *img = [UIImage imageNamed:@"anicon.png"];
UIImageView *alternate = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,70,70)];
alternate.image = img;
UILabel *alternatelabel = [[UILabel alloc] initWithFrame:CGRectMake(75,0,210,70)];
alternatelabel.backgroundColor = [UIColor clearColor];
UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(75, 20, 225, 70)];
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.text = [NSString stringWithFormat:@"%@ - %@", articleDateString, entry.blogTitle];
detailLabel.font = cellFont2;
alternatelabel.font = cellFont;
alternatelabel.text = entry.articleTitle;
[cell.contentView addSubview:alternate];
[cell.contentView addSubview:alternatelabel];
[cell.contentView addSubview:detailLabel];
[detailLabel release];
[alternatelabel release];
[alternate release];
NSLog(@"imageurl%@", img);
return cell;
}