0

I'm working on an iPad app in a split view controller where the app will remain in landscape the entire time. I would like the root view controller to remain a list and the detail view controller to swap out 4 different views controlled by a UISegmentedControl.

I'm following this post here UISegmentedControl Best Practice, however when I swap in my view controllers, they don't properly fit in the detailview controller, they are cut off as if they are trying to draw for ipad portrait orientation.

If I completely ignore the segmented control approach and have a detail view, the view size properly in the detail view, but once i try to swap them in with a segmented control is where I run into trouble.

Is there a way to tell the swapped in views to draw correctly?

Community
  • 1
  • 1
Convolution
  • 2,351
  • 17
  • 24
  • aside: "will remain in landscape the entire time" this is, of course, against suggested practice. it's preferable to let the user decide how they prefer to work - that said, on first shot mockup, it's okay to ignore this suggestion – bshirley Jul 28 '11 at 16:53

2 Answers2

1

Have you tried:

swappedInView.frame = detailController.view.bounds;

when you call

[detailedController.view addSubview:swappedInView];

?

Their contents need to have their resizing behaviors (most easily in xcode/IB) set appropriately.

bshirley
  • 8,217
  • 1
  • 37
  • 43
  • That did the trick, didn't realize that my subviews weren't inheriting their parent views frame. Thank you for pointing this out, I'm embarrassed to say I missed it. – Convolution Jul 28 '11 at 23:05
0

I am using a UISegmentControl as well, but adding my views programmatically. I have my default view (segment 0) loaded first in the viewDidLoad of the rootController. Then based on which segment is pressed, I check if the view has been initialized, if not, initialize, then add it as a subview. Then remove the other view. I had a similar post on this on how to keep track of it that might help you out, and has the code from Beginning iPhone 4 Development book that I used for my own app. Here's the code snippet to get you started if you want to go this approach:

if (self.yellowViewController.view.superview == nil)
{
    if (self.yellowViewController == nil)
    {
        YellowViewController *yellowController =
        [[YellowViewController alloc] initWithNibName:@"YellowView"
bundle:nil];
        self.yellowViewController = yellowController;
        [yellowController release];
    }
    [blueViewController.view removeFromSuperview];
    [self.view insertSubview:yellowViewController.view atIndex:0];
}
else
{
    if (self.blueViewController == nil)
    {
        BlueViewController *blueController =
        [[BlueViewController alloc] initWithNibName:@"BlueView"
bundle:nil];
        self.blueViewController = blueController;
        [blueController release];
    }
    [yellowViewController.view removeFromSuperview];
    [self.view insertSubview:blueViewController.view atIndex:0];
}

In my own, I add as a subview, instead of inserting it behind the other views (they had a toolbar in the front in their example). So if say segment 3 was pressed, then I would check the other views if their superviews were present, remove that view, add my view. Hope that helps.

Crystal
  • 28,460
  • 62
  • 219
  • 393