2

I have a containerView with an embedded viewController. Sometimes I need to perform the embed segue again with different sender but I'll get this error:

'There are unexpected subviews in the container view. Perhaps the embed segue has already fired once or a subview was added programmatically?'

Is it possible to to perform a embed segue multiple times or not?!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
NabiMo
  • 105
  • 9
  • 1
    It is not. You can instantiate a new view controller instance and replace the current instance in the container, but you can't do it via a segue – Paulw11 Jun 10 '18 at 09:31

1 Answers1

1

You just need to make sure to programmatically cleanup the previously embedded view controller as described in the second part of https://stackoverflow.com/a/32166435/1049134:

   [self.containedViewController willMoveToParentViewController:nil];  
   self.containedViewController.view removeFromSuperView];
   [self.containedViewController removeFromParentViewController];

The next time you trigger your embed segue it will work just like it did the first time.

Rivera
  • 10,792
  • 3
  • 58
  • 102