0

popoverController として表示する tableView のサイズを 4*rowheight に設定しました。そして、tableViewで12セルを使用しています。各セルには、画像とラベルが含まれています。スクロールするとすべてのセルが表示されます。5番目のセルまでは問題ありません。th2 5 番目のセルの後、最初の 4 つのセルで使用しているラベルと画像が、残りのセルに対して繰り返されます。セルを選択すると、結果が正確に表示されます。

しかし、もう一度 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"];
}
   }
4

2 に答える 2

1

ああ、ウルヴァリン、あなたはばかげた間違いをしています:

基本的に、ラベルの値を設定しています

    if(cell==nil){
}

ブロック。したがって、値は再利用され、セルごとに設定されないため、繰り返されます。

indexpath を使用してこのブロックの外側に値を設定する必要があり、それに応じて変更が反映されます。

お役に立てれば、

ありがとう、

マドゥップ

于 2010-05-07T11:19:14.203 に答える
0

すべてのテーブルに imageView.image と label.text を提供する必要があります。

UIImageView *imageView = (UIImageView *)[cell viewWithTag:IMAGE_TAG];
UILabel *mylabel = (UILabel *)[cell viewWithTag:LABEL_TAG];

if (row == 0)
{
    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"cover_v.jpg"]];
    mylabel.text = [NSString stringWithFormat:@"COVER PAGE"];
}
else
{
    imageView.image = // ???
    mylabel.text = // ??
}

そしてもちろん、そのコードは「if (cell == nil) {...}」フレームの外にある必要があります。

于 2010-05-07T13:05:23.450 に答える