2013-02-20 82 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]); 
相關問題