1

When the purchaseButton is chosen it starts the process of purchasing an IAP, which will segue the user to the next ViewController.

I need to figure out how to get the segue to hold off on sending the user to the next ViewController until the IAP transaction has completed.

Any suggestions? Will post any extra code as needed. Thanks!

Segue

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.

    if ([segue.identifier isEqualToString:@"leaguesEdit"]) {

        UIButton *button = (UIButton *)sender;
        MREditLeaguesViewController *levc = (MREditLeaguesViewController *)segue.destinationViewController;
        levc.buttonNumber = (int)button.tag;
        NSLog(@"LEVC #: %d", (int)button.tag);
    }
    else if ([segue.identifier isEqualToString:@"nothing"]) {
        // Nothing
    }
}

The segue is hooked up from the ViewController. And the IBAction it sits in is:

- (IBAction)purchase:(id)sender {
    [self purchaseProduct:[validProductsInStore objectAtIndex:0]];
    NSLog(@"IBAction Purchase");

    [self performSegueWithIdentifier:@"leaguesEdit" sender:sender];
}
Realinstomp
  • 532
  • 2
  • 13
  • 30

2 Answers2

3

You could simply connect the segue in storyboard, but from view controller to view controller. Then you can call the segue programmatically once you are ready:

[self performSegueWithIdentifier:@"leaguesEdit" sender:nil];
Mundi
  • 79,884
  • 17
  • 117
  • 140
  • The wording in this answer is a little confusing, but the idea is, in storyboard, the segue source should be the view controller rather than the button, and then you call the segue programmatically. – nhgrif Jul 05 '14 at 00:13
  • Thanks so much for the response! I actually already had the segue hooked up in the storyboard like that. The part I'm having a hard part with is the `StoreKit` delegates and where exactly I would put the `[self performSegueWithIdentifier:@"leaguesEdit" sender:nil];`... currently I have it in the `purchase` action posted above, but that still starts segueing before the purchase is actually complete. So I'm not sure where in the `StoreKit` delegates or wherever else is the best place to put `[self performSegueWithIdentifier:@"leaguesEdit" sender:nil];`. Does that make sense? – Realinstomp Jul 05 '14 at 16:49
1

Instead of connecting and creating segue from your Button directly, you can connect all those segues from the View Controller button, lying below your view in your storyboard. In this case, you will have multiple segues and none of them will be individually connected to any of the controls. You can now use this below line of code at the point where you actually want to perform the segue.

[self performSegueWithIdentifier:@"yourSegue" sender:nil];

Look out for the yellow button below your View Screen in your storyboard.

Drag and drop a segue from that button onto the View Controller that you want to connect. And when the above line of code is encountered, the prepareForSegue will be called automatically.

Hope this helps.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34
  • Thanks so much for the response @iCoder! I actually already had the segue hooked up in the storyboard like that. The part I'm having a hard part with is the `StoreKit` delegates and where exactly I would put the `[self performSegueWithIdentifier:@"leaguesEdit" sender:nil];`... currently I have it in the `purchase` action posted above, but that still starts segueing before the purchase is actually complete. So I'm not sure where in the `StoreKit` delegates or wherever else is the best place to put `[self performSegueWithIdentifier:@"leaguesEdit" sender:nil];`. Does that make sense? – Realinstomp Jul 05 '14 at 16:49