テーブルビュー cell のカスタム セルを作成しています。customcell クラスに条件を記述しています。indexpath.row=0 の場合、セルに 2 つの画像を作成し、そうでない場合は 3 つの画像を作成します
私のカスタムセルクラス
if (appDelegate.rowIndex==0)
{
UIButton *lObjImageButton=[UIButton buttonWithType:UIButtonTypeCustom];
lObjImageButton.frame=CGRectMake(150*0+12.5, 5, 150-10, 290 - 120+10);
[lObjImageButton setBackgroundColor:[UIColor greenColor]];
//lObjImageButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:lObjImageButton];
UIButton *lObjImageButton1=[UIButton buttonWithType:UIButtonTypeCustom];
lObjImageButton1.frame=CGRectMake(150*1+10+5, 5, 150-10, 170+10);
[lObjImageButton1 setBackgroundColor:[UIColor redColor]];
//lObjImageButton1.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:lObjImageButton1];
imageButtonArray = [[NSArray alloc] initWithObjects:lObjImageButton, lObjImageButton1, nil];
}
else
{
UIButton *lObjImageButton=[UIButton buttonWithType:UIButtonTypeCustom];
lObjImageButton.frame=CGRectMake(150*0+12.5, 5, 150-10, 290 - 120+10);
[lObjImageButton setBackgroundColor:[UIColor greenColor]];
//lObjImageButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:lObjImageButton];
UIButton *lObjImageButton1=[UIButton buttonWithType:UIButtonTypeCustom];
lObjImageButton1.frame=CGRectMake(150*1+10+5, 5, 150-10, 170+10);
[lObjImageButton1 setBackgroundColor:[UIColor redColor]];
//lObjImageButton1.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:lObjImageButton1];
UIButton *lObjImageButton2=[UIButton buttonWithType:UIButtonTypeCustom];
lObjImageButton2.frame=CGRectMake(150*2+10+5, 5, 150-10, 170+10);
[lObjImageButton2 setBackgroundColor:[UIColor blueColor]];
//lObjImageButton1.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:lObjImageButton2];
imageButtonArray = [[NSArray alloc] initWithObjects:lObjImageButton, lObjImageButton1,lObjImageButton2, nil];
}
ここで appdelegate.rowindex の値は、viewcontroller の内部の cellforrowindex で appdelegate.rowstauts=indexpath.row として設定しています。
アプリケーションを実行すると、プロジェクトは私の希望どおりに実行されます.1番目のセル2つの画像と残りのセル3つの画像ですが、スクロールすると条件が一致せず、6番目のセルが2つの画像になり、合計3つのセルが2つの画像になり、私の最初のセルは 3 つの画像になります..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
BSImageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
appDelegate.rowIndex=indexPath.row;
NSLog(@"cell.index= %i",cell.index);
if (cell == nil) {
cell = [[BSImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
問題はスクロールで発生します。