首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将nsmutablearray类型转换为skproduct - ios类型无效

将nsmutablearray类型转换为skproduct - ios类型无效
EN

Stack Overflow用户
提问于 2013-02-21 02:09:24
回答 2查看 227关注 0票数 0

我收到"invalid cast type nsmutablearray to type skproduct“错误。当我尝试将产品添加到我的uitableview时..这是我正在使用的代码...

初始化

代码语言:javascript
复制
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];

......
}

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-21 02:19:48

你试过了吗?

代码语言:javascript
复制
SKProduct *product = (SKProduct *)[_products objectAtIndex:indexPath.row];
票数 1
EN

Stack Overflow用户

发布于 2013-02-21 02:26:22

虽然我自己不能复制它,但我可以推断编译器认为您正在尝试强制转换_products,而不是您从_products访问的对象。将整个内容包含在一组括号中,这样编译器就知道将表达式作为一个整体进行计算。

代码语言:javascript
复制
SKProduct *product = (SKProduct*)(_products[indexPath.row]);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14986929

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档