Question

Before the Main View Controller is called, through a delegate I'll notify Main View Controller whether to call TVC1 or TVC2 in Container View.

Question: How can I programmatically tell the Container View in Main View Controller to call TVC1 or TVC2?

TVC1 *tvc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"TVC1"]; 
TVC2 *tvc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"TVC2"];

Where and how do I tell the Container View to load one of these controllers upon loading Main View Controller?

enter image description here

Was it helpful?

Solution

through delegate u can know which view will be added so u can manage it by using any bool value n in viewDidLoad you can load that view by putting one condition

in mainController:

bool isFirstView;

-(void)delegate:(bool)isFirst
{
  isFirstView = isFirst;
}

// in viewDidLoad 
)
(void)viewDidLoad
{
  if(isFirstView)
  {
    TVC1 *tvc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"TVC1"]; 
  }
  else
  {
    TVC2 *tvc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"TVC2"];
  }
}

OTHER TIPS

You can do this by using custom Container View Controller which will manage child view controllers.

enter image description here

There is a good tutorial for that:

http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top