What you can do, Have one Main ViewController with segment, SayMainViewC
and take two different View Controllers say ViewAVC
and ViewBVC
inside this MainViewC
Add All your subviews that you want to show in ViewA and ViewB.
Add these View Controllers to MainViewC
with setting a proper frame for each ViewController.
Now while you add the segmentControl You can add a target function in the following way
itemArray = [NSMutableArray arrayWithObjects: @"Zero", @"One", nil];
seg = [[UISegmentedControl alloc] initWithItems:itemArray];
[seg setFrame:segRect];
seg.segmentedControlStyle = UISegmentedControlStyleBar;
seg.momentary = NO;
[seg addTarget:self action:@selector(someAction:) forControlEvents: UIControlEventValueChanged];
[mainView addSubview:seg];
In this function someAction:
check what is the currently selected value of the segment and Hide one view and unhide other.
This way you will have seperate View Controller, but when you wish to interact between these View Controllers and MainViewC
you will require to add a few delegates