1

In my app, I need to have a splitView and to be able to insert my own views to the panes.

To that end, in the Interface builder i have created a SplitView with two dividers (three panes), and added the "Custom Views" that are in those three panes as IBOutlets to my corresponding view controller. However, when I query the IBOutlets for their frame/bounds sizes, they are all 0.00000.

Why do the custom views I created in Xcode have 0 size? How can I fix that?

UPD: the code to query the frame/bounds of the panes:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.logList = [[LogListViewController alloc] initWithNibName:LOGLISTXIB bundle:nil];
        [self logARect:self.leftPane.bounds withName:@"LeftPane bounds"];
        [self logARect:self.leftPane.frame withName:@"LeftPane Frame"];
    }
}
- (void) logARect:(NSRect) theFrame withName:(NSString *)name {
    NSLog(@"%@ frame: %lf, %lf, %lf, %lf", name, theFrame.origin.x, theFrame.origin.y, theFrame.size.width, theFrame.size.height);
}

UPD2 At the same time, when I access the panes by self.view.subviews[0], i get the correct size.

Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
Ibolit
  • 9,218
  • 7
  • 52
  • 96

2 Answers2

1

The views are probably not laid out yet when you try to get the positions. The viewDidLoad in NSViewController? question points out that loadView should be used to modify the view's layout. This answer in the same question shows a trick to make your Cocoa code similar to the Cocoa-touch one.

Community
  • 1
  • 1
allprog
  • 16,540
  • 9
  • 56
  • 97
  • It is Cocoa, now I have added the corresponding tag. As far as I know there is no corresponding method in Cocoa. – Ibolit Jun 26 '13 at 10:55
  • Not yet. But I am now just doing all the set-up programmatically instead of wiring it up in IB. It serves my purpose, but it doesn't answer the original question. – Ibolit Jun 27 '13 at 20:48
  • Are you sure the `leftPane` is wired up correctly? Did you check if it is not null or something unexpected? Can you share some code? Does it have the correct size in a later time in the execution? – allprog Jun 28 '13 at 07:21
  • Yes, I did check all that. You can find the answer I have found as a reply to my own question. Thanks for your help anyway ) – Ibolit Jun 30 '13 at 17:43
  • Well, then in fact my answer is also legit in some way. I've spent quite some time with this issue, so a single up vote would make me happier... – allprog Jun 30 '13 at 17:48
1

Turns out, the initializer is not the place to query the size of views, or so it seems. When I check the sizes of views in the -awakeFromNib method, they are correct. It seems logical.

Ibolit
  • 9,218
  • 7
  • 52
  • 96