Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present view controller using Storyboards

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

  1. Button to 'Buy item'
  2. Screen comes up that allows user to select product

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];

}

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

Do I need to change something?

EDIT:

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];

    }

enter image description here

like image 809
Omar Avatar asked Nov 30 '22 19:11

Omar


1 Answers

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

enter image description here

in this example Custom Class should be: PurchasedViewController

and this is the code:

 - (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];
 }
like image 131
Ilario Avatar answered Dec 09 '22 09:12

Ilario