このコードの何が問題なのかわかりませんが、ボタンを追加しなかったセル (追加する必要があるかどうかを確認する場合) で、下にスクロールしてからもう一度上にスクロールすると、ボタンが表示されます。 .
これは、テーブルビューのセル生成関数のコードです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CLASSshopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"shopCell"];
SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.titleCell.text = product.localizedTitle;
cell.descCell.text = product.localizedDescription;
[_priceFormatter setLocale:product.priceLocale];
cell.priceCell.text = [_priceFormatter stringFromNumber:product.price];
// already yours, so no cart button
if ([[CLASSIAPHelper sharedInstance] productPurchased:product.productIdentifier]) {
cell.priceCell.text = @"Already yours";
} else {
UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *btn = [UIImage imageNamed:@"cart.png"];
UIImage *btnh = [UIImage imageNamed:@"cartHover.png"];
[buyButton setBackgroundImage:btn forState:UIControlStateNormal];
[buyButton setBackgroundImage:btnh forState:UIControlStateHighlighted];
buyButton.frame = CGRectMake(cell.bounds.size.width - 40,40, 24, 24);
buyButton.tag = indexPath.row;
[buyButton addTarget:self action:@selector(buyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:buyButton];
}
return cell;
}
何も特別なことに気付かなかったものをログに記録します。状態は常に検証されます。何か考えはありますか?