1

I have a NSSplitView as my "Superview". In this SplitView is a Custom View with a NSTableView. I'm try to load my Custom View from a Controller class and then adjust the size of the custom view and the Table. But the table and or the custom view don't get resized. What i'm doing wrong?

Here is my controller class method where i load and set the size of the custom view:
// Header File @property (weak) IBOutlet NSView *navigationView; @property (strong) AppsNavigationViewController *navigationViewController;

// Implementation
- (void) initNavigationView :(id)viewControllerClass :(NSString*) viewNibName {

  _navigationViewController = [[viewControllerClass alloc] 
                               initWithNibName:viewNibName bundle:nil]; 

 // add the current custom view to the parent view
 [_navigationView addSubview:[_navigationViewController view]];

 [[_navigationViewController view] setAutoresizingMask:
                                    NSViewHeightSizable|NSViewWidthSizable];

 // set the bounds of the custom view to the size of the parent view
 [[_navigationViewController view] setBounds:[_navigationView bounds]]; 

 [_navigationViewController setDelegate:self]; // not relevant

 [_splitView adjustSubviews]; // checked. contains the _navigationView

}

And here is how it looks:

nssplitview with custom view and nstable

EDIT I subclassed some views and draw different backgrounds. And it's definitely the custom view which don't get the size!

enter image description here

Togo
  • 172
  • 8

1 Answers1

1

It seems maybe your table's frame is not at the origin of its super view. First, try setting the frame instead of the bounds and you could call this after you do that.

[[_navigationViewController view] setFrameOrigin:NSMakePoint(0,0)];

Normally though I usually set the frame/bounds like this because your superview's bounds may not be at {0,0} of its superview...

NSRect newFrame;
newFrame.origin.x = 0;
newFrame.origin.y = 0;
newFrame.size.width = [[someView superview] frame].size.width;
newFrame.size.height = [[someView superview] frame].size.height;
[someView setFrame:newFrame]; 
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Thanks regulus. But still the same behaviour. It's definitely that my custom view don't get the correct size!! See the edit in the post – Togo Jan 18 '13 at 05:21
  • 1
    Have you tried using setting the frame instead of bounds or do you have any other methods which affect these properties? – regulus6633 Jan 18 '13 at 12:09
  • And maybe remove the call to the splitView. – regulus6633 Jan 18 '13 at 12:15
  • Got it. I have to call the setFrame instead of the setBounds method. thanks a lot. That was the hint i needed. Can you edit your question so in can mark them as the answer? – Togo Jan 18 '13 at 12:27