0

I'm searching if there is any way to present two or more controllers at once.

Something like with navigation controller: https://stackoverflow.com/a/28464115/5790492

But for modal controllers. Now i just do presentViewController:animated:false in first controller and another presentViewController:animated:true in second controller. But get error:

Unbalanced calls to begin/end appearance transitions for

And I see first ViewController before animation of second. This is not pretty. It would be perfect if when i use method:

- (void)presentInController:(UIViewController *)current controllerA:(UIViewController *)controllerA controllerB:(UIViewController *)controllerB;

In the screen - there would be switching to controllerB with animation. And it would be possible to dismiss him to controllerA.

Community
  • 1
  • 1
Nik Kov
  • 10,605
  • 4
  • 56
  • 96
  • so just load them not on screen, you can set their frames to be outside at the begiining and when they will load animate them to the front – Lu_ Jan 11 '17 at 10:41
  • Do you want them to be at the screen at the same time, like side by side for example? Have you looked into this https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html ? – Losiowaty Jan 11 '17 at 10:48

2 Answers2

1

Use ContainerView is one way that I can think of. Basically you drag 2 ContainerView and each of these point to the 2 Viewcontroller that you want to show by way of "embed" (as normally you would do it). There is really no code to this, as it is as straight forward as dragging the ContainerView object from IB and drop in onto your main view in Storyboard.

GeneCode
  • 7,148
  • 7
  • 42
  • 75
  • 1
    Answer is too blur (though is correct). Please provide code snip and further information – OhadM Jan 11 '17 at 13:05
  • Ok I add more details. But containerview really don't have any codes to it. It's a drag and drop item. – GeneCode Jan 12 '17 at 02:20
-1

You can use GCD to avoid Unbalanced calls to begin/end appearance transitions for error.

//delayInSeconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //code to be executed after a specified delay
    UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerName"];
    [self presentViewController:vc animated:false completion:nil];
});

change the delayInSeconds as per you want.

it could be like this,

  • presentViewController:animated:false
  • another presentViewController:animated:true with GCD delay
Antony Raphel
  • 1,700
  • 2
  • 20
  • 44
  • Unbalanced calls is a product of presenting VC before the actual hierarchy was pushed which is viewDidAppear. Your solution isn't a solution but a temp fix which is a bad practise. – OhadM Jan 11 '17 at 11:00
  • 1
    Sorry, but i don't need that delay and this is the main question. – Nik Kov Jan 11 '17 at 12:11
  • @NikKov otherwise use delegate methods to dismiss and present another viewcontroller. – Antony Raphel Jan 11 '17 at 12:15