views:

156

answers:

0

Hi,

I'm trying to do the following:

alt text

I need to do a lot of custom things, so I subclassed everything.

alt text

I'm having issues with autoresize and positioning. For instance the UIToolBar is not at the correct position. So here is the question: If you don't use UITableViewController or any other Controller, that takes care of all the positioning and sizing, then you have to do it yourself. Can someone someone tell me how this works? What do I need to understand?

---- UPDATE:

My custom goals are actually not that important as my question is actually about something else. But OK. So all "elements" like the TableView, the Toolbar and the TabBar will have custom backgrounds and use custom buttons. The TableView will be GroupedStyle and the groups can be collapsed.

My question is how do I have to structure my code especially regarding positioning and autoresizing in order to achieve what you can see in picture #1.

This is how it's structured right now:

Application Delegate:
- (void) loadView {
  RootViewController *rootView = [[RootViewController alloc] init];
  [window addSubview:rootView.view];
  [window makeKeyAndVisible];

RootViewController:
- (void) loadView {
  self.theView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  self.theView.autoresizesSubviews = YES;
  self.theView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
  self.view = self.theView;

  ChildViewController *childView = [[ChildViewController alloc] init];

  [self.view addSubview:childView.view];

ChildViewController:
- (void) loadView {
  self.theView = [[UIView alloc] init];
  self.view = self.theView;
}
- (void) viewDidLoad {
  self.view.frame = [[UIScreen mainScreen] bounds];
  CGRect toolbarBounds = self.theToolbar.bounds;
  CGRect viewBounds = self.view.bounds;
  CGRect tableViewBounds = CGRectMake(0, CGRectGetHeight(toolbarBounds), CGRectGetWidth(viewBounds), CGRectGetHeight(viewBounds) - CGRectGetHeight(toolbarBounds));

  self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

  self.theTableView = [[MyTableView alloc] initWithFrame:tableViewBounds 
                                                  style:UITableViewStyleGrouped 
                                                 parent:self];


  [self.view addSubview:self.theToolbar];
  [self.view addSubview:self.theTableView];
}

MyToolBar:
- (id)initWithParent:(id)theParent {
  if ((self = [self init])) {    
    self.parent = theParent;

    CGRect rectArea = CGRectMake(0, 0, CGRectGetWidth([[[self parent] view] bounds]), 44);
    [self setFrame:rectArea];

    self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

    [self loadButtons];
  }
  return self;
}

So this is how the positioning is structured at the moment (messy). It actually works, BUT I have a ModalView which is handled by the ChildViewController. When I have the iPad in Portrait view and I pop up the modal view and dismiss it, then everything works. But when I do the same on Landscape view it rotates the hole view... the ChildViewController by 90 degrees when dismissing the modal view. Very strange. When I load directly ChildViewController in my AppDelegate, then again everything works fine.