我已将显示为 popoverController 的 tableView 的大小设置为 4*rowheight。我在 tableView 中使用了 12 个单元格。每个单元格包含一个图像和一个标签。我可以通过滚动查看所有单元格。直到第 5 个单元格都可以。在第 5 个单元格之后,我在前四个单元格中使用的标签和图像正在为剩余的单元格重复。如果我选择单元格,结果会准确显示。
但是当我再次使用 tableView 时,即使前 5 个单元格的图像和标签也不准确。一切都改变了,但选择给出了正确的结果。谁能帮我??
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [self tableviewCellWithReuseIdentifier:CellIdentifier rowNumber:indexPath.row];
}
//tableView.backgroundColor = [UIColor clearColor];
return cell;
}
- (UITableViewCell *)tableviewCellWithReuseIdentifier:(NSString *)identifier rowNumber:(NSInteger)row
{
CGRect rect;
rect = CGRectMake(0.0, 0.0, 360.0, ROW_HEIGHT);
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:rect reuseIdentifier:identifier] autorelease];
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.00, 10.00, 150.00, 100.00)];
myImageView.tag = IMAGE_TAG;
[cell.contentView addSubview:myImageView];
[myImageView release];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(170.00, -10.00, 170.00, 80.00)];
label.tag = LABEL_TAG;
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor blackColor]];
[label setFont:[UIFont fontWithName:@"AmericanTypewriter" size:22]];
[label setTextAlignment:UITextAlignmentLeft];
[cell.contentView addSubview:label];
[label release];
if (row == 0)
{
UIImageView *imageView = (UIImageView *)[cell viewWithTag:IMAGE_TAG];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"cover_v.jpg"]];
UILabel *mylabel = (UILabel *)[cell viewWithTag:LABEL_TAG];
mylabel.text = [NSString stringWithFormat:@"COVER PAGE"];
}
}