これは、テーブルビューのセルをロードするための私のコードです:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CellView" owner:self options:nil];
cell = nibLoadedCell;
}
if (photosArray.count > 0) {
for (int i = 1; i < 4; i++) {
UIButton *button = (UIButton *)[cell viewWithTag:i];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.layer.borderWidth = 2;
button.layer.cornerRadius = 5;
button.clipsToBounds = YES;
//Add images to the button
UIImage *btnImg;
if ((indexPath.row * 3) + i < photosArray.count) {
btnImg = [photosArray objectAtIndex:((indexPath.row) * 3 + i)];
NSLog(@"%d",(indexPath.row) * 3 + i);
}
[button setBackgroundImage:btnImg forState:UIControlStateNormal];
button.tag = imageButtonTag;
imageButtonTag--;
}
}
NSLog(@"%d",cell.contentView.subviews.count);
for (UIButton *button in cell.contentView.subviews) {
if ([button backgroundImageForState:UIControlStateNormal] == nil) {
[button removeFromSuperview];
}
}
return cell;
}
3 つのボタンを保持する作成したカスタム セルが既にあります。
また、さまざまな画像の配列があります。
上記のコードは、各セルに 3 つのボタン/ を備えたテーブルビューを作成し、各ボタンには背景画像があります。
問題は、下にスクロールすると、一部の画像が繰り返されることがわかります。それは写真のソース配列から来ることはできませんでした.私の配列が問題ないことは 99% 確信しています.
誰かが私が間違っていることを見ることができますか? 私はそれを長い間見てきました、そして私は私の間違いを見ることができません..
ありがとう