我不确定这段代码有什么问题,但是在我没有添加按钮的单元格中(我有一个如果检查我是否需要添加它)按钮在向下滚动然后再次向上滚动后出现.
这是表格视图中单元格生成功能的代码。
- (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;
}
记录一些我没有注意到什么特别的东西,条件总是得到验证。你有什么主意吗?