我收到"invalid cast type nsmutablearray to type skproduct“错误。当我尝试将产品添加到我的uitableview时..这是我正在使用的代码...
初始化
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];
......
}我的错误是什么?谢谢..
发布于 2013-02-21 02:19:48
你试过了吗?
SKProduct *product = (SKProduct *)[_products objectAtIndex:indexPath.row];发布于 2013-02-21 02:26:22
虽然我自己不能复制它,但我可以推断编译器认为您正在尝试强制转换_products,而不是您从_products访问的对象。将整个内容包含在一组括号中,这样编译器就知道将表达式作为一个整体进行计算。
SKProduct *product = (SKProduct*)(_products[indexPath.row]);https://stackoverflow.com/questions/14986929
复制相似问题