我在init方法中有appdelegate请求AppStore产品的详细信息,我希望将应用内购买产品的价格显示在popover内的按钮中。
我已经设置了正确返回产品数组的请求,以及包含价格的字符串。我的问题是popover视图控制器在AppStore回复之前创建视图,标题标签用(null)初始化。如果我可以延迟按钮标题集,我会确定请求确实得到了回复,但这会导致应用程序崩溃。
我的要求是
- (void)requestProUpgradeProductData {
NSSet *productIdentifiers = [NSSet setWithObject:@"com.thePrintLabs.product"];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
}
然后我读了回复:
NSArray *products = response.products;
proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;
if (proUpgradeProduct)
{
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
priceWeek = [NSString stringWithString:[formatter stringFromNumber:proUpgradeProduct.price]];
}
popOverViewController中的我这样做是为了设置按钮标题:
myAppDelegate *delegate = (myAppDelegate*)[[UIApplication sharedApplication] delegate];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(button1Week:)
forControlEvents:UIControlEventTouchDown];
NSString *priceWeekly = [NSString stringWithFormat:@"Weekly %@",delegate.priceWeekly];
[button setTitle:priceWeekly forState:UIControlStateNormal];
我的按钮始终用(null)初始化。请求成功后我可以更新按钮吗?