Cocoa NSTabView Coding Style Question

I have a question about the coding style, which should probably be asked to a senior programmer in the workplace, but since I'm the only Mac programmer, well, that’s the way it is. I have a pop-up graphical interface for my software (3D models, data visualization), and the pop-up menu is mainly a tab control with tons of material on each tab (sliders, radio buttons, checkboxes, etc.). With something like 20 tab controls and maybe half a dozen tabs ... using one controller for all views will be very fast.

Is there a MainViewController that loads a bunch of good Tabs styles?

NSView *tabA = [[NSView alloc] initWithNibName:@"tabA.nib" bundle:[NSBundle bundleWithPath:@"/Applications/BOB.app"]]; NSView *tabB = [[NSView alloc] initWithNibName:@"tabB.nib" bundle:[NSBundle bundleWithPath:@"/Applications/BOB.app"]]; 

I like the way I do it on iOS, but I'm not sure about Mac OS X. I prefer a style that offers convenience and flexibility, as the code goes through prototyping, and I may have to change it often.

If this is not a good style, what is it?

Thanks!

+1
source share
1 answer

I think your reasonable style. You subclass NSViewController for each tab and assign it to NSTabView using NSTabViewItem .

By the way, I think it's better to have

 NSViewController *tabAcontroller = [[TabAController alloc] init]; 

with @interface TabAController:NSViewController ... @end with init denoted as

 -init{ self=[super initWithNibName:@"tabA" bundle:nil]; if(self){ ... } return self; } 

Note that you do not need the .nib extension when you call initWithNibName:bundle: And you should not specify a hard-coded path to the application. In iOS, the position of the application is set by the OS (with the names of the cryptographic folders), but in OS X the user can freely move the application package anywhere he wants. Therefore, never refer to the core set as [NSBundle bundleWithPath:@"hard coded path"] . Use only [NSBundle mainBundle] or just nil in most cases. It is written in the documentation when you can just use nil .

+2
source

All Articles