1

我正在从http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial购买应用程序。当我尝试在reload方法之外打印产品数组时出现错误。我想在我的 menuitem 操作中使用这个产品数组。它还向我显示了数组的正确大小,但是当我尝试打印或使用该数组中的产品时,它给了我一个错误。

-(id) init
{
  if( (self=[super init]))
  {
    isTouchEnabled=YES;
    startY=120;
    startX=90;

    CCMenuItemImage *menuitem1 = [CCMenuItemImage itemFromNormalImage:@"100.png"                                      selectedImage:@"100.png" target:self selector:@selector(buy100C:)];
    CCMenuItemImage *menuitem2 = [CCMenuItemImage itemFromNormalImage:@"220.png"   selectedImage:@"220.png" target:self selector:@selector(buy220C:)];
    CCMenuItemImage *menuitem3 = [CCMenuItemImage itemFromNormalImage:@"350.png" selectedImage:@"350.png" target:self selector:@selector(buy350C:)];
    CCMenuItemImage *menuitem4 = [CCMenuItemImage itemFromNormalImage:@"500.png" selectedImage:@"500.png" target:self selector:@selector(buy500C:)];
    CCMenuItemImage *menuitem5 = [CCMenuItemImage itemFromNormalImage:@"1800.png" selectedImage:@"1800.png" target:self selector:@selector(buy1800C:)];
    CCMenuItemImage *menuitem6 = [CCMenuItemImage itemFromNormalImage:@"3000.png" selectedImage:@"3000.png" target:self selector:@selector(buy3000C : )];
    CCMenuItemImage *menuitem7 = [CCMenuItemImage itemFromNormalImage:@"back2.png" selectedImage:@"back2.png" target:self selector:@selector(back)];
    CCMenu *menu = [CCMenu menuWithItems:menuitem1,menuitem2,menuitem3,menuitem4,menuitem5,menuitem6,menuitem7, nil];
    [menu alignItemsVerticallyWithPadding:2];
    menu.position=ccp(startX, startY);
    menu.scale=.55;
    [self addChild:menu];
    [RageIAPHelper sharedInstance];
    [self reload];
}

return self;

}
-(void)reload
{
[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success,   NSArray *products) {
    if (success) {

            _products = products;

        NSLog(@"produts==%d",[_products count]);
         NSLog(@"product===%@",_products);
        for (SKProduct * skProduct in _products) {
            NSLog(@"Found product: %@ %@ %0.2f",
                  skProduct.productIdentifier,
                  skProduct.localizedTitle,
                  skProduct.price.floatValue);
        }

    }
   }];
}
-(void)buy100C:(id) sender
{

 NSLog(@"hisize=======%d",[_products count]);
 if([_products count] >=8){
  NSLog(@"product===%@",_products);//this line is giving error and app stop.
}
}

在 buy100C 方法中,我没有从阵列中获取产品。

4

0 回答 0