2013-02-20 80 views
0

我得到“无效的投影类型nsmutablearray键入skproduct”错误..当我尝试将产品添加到我的uitableview ..这里是我使用的代码...无效的投射类型nsmutablearray类型skproduct - ios

初始化

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]; 

...... 
} 

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

+0

我无法使用您的示例在我的机器上复制它。尝试一个干净的重建。 – CodaFi 2013-02-20 18:23:15

回答

1

你试过

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

虽然我不能复制它自己,我可以推断,编译器认为你想投_products,而不是对象,你已经从访问_products。将整个东西包装在一组括号中,以便编译器知道将表达式评估为一个整体。

SKProduct *product = (SKProduct*)(_products[indexPath.row]); 
相关问题