2

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

user1107173
  • 10,334
  • 16
  • 72
  • 117

2 Answers2

1

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"];
  }
}
Yuri Solodkin
  • 530
  • 8
  • 26
Divyam shukla
  • 2,038
  • 14
  • 18
  • I'm struggling with the code. How do I tell the Container View what controller it should load? TVC1 *tvc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"TVC1"]; TVC2 *tvc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"tvc2"]; Now where and how do I load these controllers? – user1107173 Oct 02 '13 at 19:08
  • it depends on u if u want to create it using storyboard then u have to maake a instance on nav controller by that u can call this tvc1 n tvc2 in view didload method by getting which view u want to load using any bool value by true or false – Divyam shukla Oct 02 '13 at 19:12
  • How does that view automatically gets called in Container View? – user1107173 Oct 02 '13 at 19:46
  • you can perform the segue by using the reference of this view controller – Divyam shukla Oct 06 '13 at 07:51
0

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

Yuri Solodkin
  • 530
  • 8
  • 26