当前视图控制器使用故事板
我已经按照教程添加在应用程序购买到我的应用程序。 有2个意见:
- button到“购买项目”
- 屏幕出现,允许用户select产品
我已经完全正确地添加了代码,但在教程中他们使用的是XIB文件,但是我正在使用Storyboard。 我的“购买商品”button的代码如下所示:
- (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]; }
我有的问题是,当button被点击时,出现一个黑色的屏幕,但我想购买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]; }
对于故事板,您应该提供一个如图所示的标识符:点击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]; }
尝试这个
_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];