我已经按照教程将In App Purchase添加到我的应用中。有2次观看次数:
我已经完全添加了代码但在教程中他们使用的是XIB文件,但我使用的是Storyboard。我的“购买项目”按钮的代码如下所示:
- (IBAction)PurchaseItem:(id)sender {
_purchaseController = [[PurchasedViewController alloc] initWithNibName:Nil bundle:nil];
_purchaseController.productID = @"com.myapp";
[self presentViewController:_purchaseController animated:YES completion:NULL];
[_purchaseController getProductID:self];
}
我遇到的问题是,当点击按钮时,会出现黑屏,但我想要BuysedViewController显示
我需要改变什么吗?
编辑:
使用已编辑的代码但收到错误:
- (IBAction)PurchaseItem:(id)sender {
PurchasedViewController *purchaseContr = (PurchasedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"menu"];
//menu is only an example
purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:purchaseContr animated:YES completion:nil];
}
答案 0 :(得分:19)
使用故事板,你应该给出如图中的标识符: 点击你的viewController和'身份检查员'
在此示例中,自定义类应为:PurchasedViewController
这是代码:
- (IBAction)PurchaseItem:(id)sender {
PurchasedViewController *purchaseContr = (PurchasedViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"menu"];
//menu is only an example
purchaseContr.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:purchaseContr animated:YES completion:nil];
}
答案 1 :(得分:0)
试试这个
_purchaseController = [[PurchasedViewController alloc] init];
_purchaseController.productID = @"com.myapp";
/* 1. Add the new VC as a child VC */
[self addChildViewController:_purchaseController];
/* 2. Add new view to source view */
[self.view addSubview:_purchaseController.view];
/* 3. Inform 'didMoveToParentViewController' to newly added view controller */
[_purchaseController didMoveToParentViewController:self];
[_purchaseController getProductID:self];