使用Storyboard呈现视图控制器 [英] Present view controller using Storyboards

查看:107
本文介绍了使用Storyboard呈现视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照教程将In App Purchase添加到我的应用中。有2次观看次数:

I have followed a tutorial to add In App Purchases to my app. There are 2 views:


  1. 按钮到'购买项目'

  2. 屏幕出现,允许用户选择产品

我已经完全添加了代码但在教程中他们使用的是XIB文件,但我使用的是Storyboard。我的购买项目按钮的代码如下所示:

I have added the code completely fine but in the tutorial they were using XIB files but I am using Storyboard. My code for the 'Buy item' button looks something like this:

- (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显示

The issue I have is that when the button is clicked, a black screen appears, but I want PurchasedViewController to show

我是否需要更改内容?

编辑:

使用已编辑的代码但收到附加错误:

Using edited code but getting error as attached:

- (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和'身份检查员'

With a storyboard you should give an Identifier like in the picture: tap on your viewController and in 'identity inspector'

在此示例中,自定义类应为: PurchasedViewController

in this example Custom Class should be: 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];
 }

这篇关于使用Storyboard呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆