Adding a subtask to a UIView element view in iPad
I am creating an app with a split view controller, the detail view has a segmented control in the navigation bar at the top. Clicking on a segment will add a new view to the detail view with appropriate information about it (hide the UIView of the DetailViewController).
I have created two new UIViews corresponding to each segment and I am trying to add them to a 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 can see that the view is showing, but it is in the wrong place, it is placed at the very top of the window, not below the navigation bar.
In IB, I instantiated views and I used the Attributes inspector to specify a "navigation bar" for the top bar that sets the view height correctly. But the view is clearly added too far in the window - I can see that the view below it (DetailViewController UIView) is peaking at the bottom (I changed the background color so I know which view I see).
Any hints on how to get the sub-item I add to position it correctly in the window?
Thanks!
a source to share
You might want to add the navigation bar in IB (or in codes) manually.
customizing the navigation bar in the top bar settings does not actually add the navigation bar and does not reserve some space for it.
anyway .. what i usually do is add 2 views in IB and then stack them neatly.
then link them to the IBOutlet. This will most likely solve your problem.
a source to share