views:

446

answers:

1

I'm creating a split view controller app, the detail view has a segmented control in a navigation bar at the top. Clicking on a segment will add a new view to the detail view with the appropriate information on it (covering up the DetailViewController's default UIView).

I've created two new UIViews, corresponding to each segment, and I'm trying to add them to the view like this (in DetailViewController.m):

if (exerciseSegmentControl.selectedSegmentIndex == UISegmentedControlNoSegment) {
    NSLog(@"No segment selected");
}
UIView *viewToShow;
if (selectedView == 0 && exerciseSegmentControl.selectedSegmentIndex == 1) {
    viewToShow = exerciseSolutionView;
}
else {
    viewToShow = exerciseView;
}
[self.view addSubview:viewToShow];

I see the view appear, but it's in the wrong place, it is placed at the very top of the window, instead of below the navigation bar.

In IB, I've created instances of the views, and I've used the Attributes inspector to specify "Navigation Bar" for top bar, which sets the height of the view correctly. But the view is clearly being added too far up in the window - I see the view below it (the DetailViewController's UIView) peaking out at the bottom (I changed the background color so I know which view I'm seeing).

Any tips on how to get the subview I'm adding to get placed correctly in the window?

Thanks!

A: 

hi. probably you might want to add Navigation Bar in IB (or in codes) manually.

setting Navigation Bar in the top bar settings doesn't really add a Navigation bar nor reserve some space for it.

anyway.. what i normally do is to add 2 views in IB, then stack them properly.

then link them wif IBOutlet. That will most probably solve your problem

Yit Ming