无效的强制转换类型nsmutablearray要输入skproduct - ios

时间:2013-02-20 18:09:24

标签: ios objective-c in-app-purchase

当我尝试将产品添加到我的uitableview时,我收到“无效的转换类型nsmutablearray来输入skproduct”错误..这里是我正在使用的代码......

初​​始化

SKProduct *product1 = [[InAppPurchaseManager sharedInAppManager] getLevelUpgradeProduct];
        SKProduct *product2 = [[InAppPurchaseManager sharedInAppManager] getPlayerUpgradeOne];
        SKProduct *product3 = [[InAppPurchaseManager sharedInAppManager] getPlayerUpgradeTwo];

        _products = [[[NSMutableArray alloc] initWithObjects:product1, product2, product3, nil] autorelease];





- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
......
        SKProduct *product = (SKProduct*) _products[indexPath.row]; // error 
        cell.textLabel.text = product.localizedTitle;
        [_priceFormatter setLocale:product.priceLocale];
        cell.detailTextLabel.text = [_priceFormatter stringFromNumber:product.price];

......
}

我的错误是什么?感谢..

2 个答案:

答案 0 :(得分:1)

你试过吗

SKProduct *product = (SKProduct *)[_products objectAtIndex:indexPath.row];

答案 1 :(得分:1)

虽然我自己无法复制,但我可以推断编译器认为您正在尝试转换_products,而不是您从_products访问的对象。将整个事物包装在一组括号中,以便编译器知道将表达式评估为一个部分。

SKProduct *product = (SKProduct*)(_products[indexPath.row]);