TableView でのセルのセットアップに問題があります...画像ビュー、2 つのラベル、1 つのタイトル、1 つの詳細を含むテーブル ビューをセットアップしました。最初の部分は問題ないように見えますが、スクロールした後、すべてのラベルが次々と積み重なっていきます。
これが私のコードです:
- (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;
}