Cocoa NSTabView编码风格问题 [英] Cocoa NSTabView coding style question
问题描述
我有一个编码风格的问题,可能应该问一个高级的Mac程序员在工作 - 但由于我是唯一的mac程序员,好吧,它是。我有一个弹出的GUI为我的软件(3D模型,数据可视化)和弹出的主要是一个Tabbed控件与大量的东西在每个选项卡(滑块,单选按钮,复选框等)与像20控制每个选项卡,并且可能六个选项卡...使用单个控制器的所有视图将会非常快速地获得。
有一个MainViewController加载一堆Tabs好样式?
NSView * tabA = [[NSView alloc] initWithNibName:@tabA.nib [NSBundle bundleWithPath:@/ Applications / BOB.app]];
NSView * tabB = [[NSView alloc] initWithNibName:@tabB.nibbundle:[NSBundle bundleWithPath:@/ Applications / BOB.app]];
这是我在iOS上的做法,但我不知道对于Mac OS X.喜欢一种提供可维护性和灵活性的样式,因为代码正在进行原型设计,我可能需要频繁更改它。
如果不是好的风格,什么是? / p>
谢谢!
您为每个选项卡创建一个 NSViewController
子类,并使用 NSTabViewItem 将其分配给
NSTabView
/ code>。
顺便说一句,我认为最好有
NSViewController * tabAcontroller = [[TabAController alloc] init];
与 @interface TabAController:NSViewController ... @end
与 init
定义为
-init {
self = [super initWithNibName:@tabAbundle:nil];
if(self){
...
}
return self;
}
请注意,您不需要扩展。当调用
。而且不应指定应用程序的硬编码路径。在iOS中,应用程序的位置是由操作系统(具有密码文件夹名称)给定的,但在OS X上,用户可以自由地将应用程序包移动到任何他想要的位置。所以,永远不要将主包作为 initWithNibName:bundle:
时,nib [NSBundle bundleWithPath:@hard coded path]
。在大多数情况下,只使用 [NSBundle mainBundle]
,或只是 nil
。它是写在文档中,当你可以使用 nil
。
I have a coding style question which probably should be asked of a senior mac programmer at work - but since I'm the only mac programmer, well, SO it is. I have a pop-up GUI for my software (3D models, data visualization) and the pop-up is Mainly a Tabbed control with a ton of stuff in each tab (sliders, radio buttons, checkboxes, etc.) With something like 20 controls per tab, and maybe half a dozen tabs... using a single controller for all the views is going to get unwieldly very quickly.
Is having a MainViewController which loads a bunch of Tabs good style?
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"]];
It's kindof how I do it on iOS, but I'm not sure for Mac OS X. I prefer a style that offers maintainability and flexibility, as the code is going through prototyping and I may need to change it frequently.
If it's not good style, what is?
Thanks!
I think yours is a reasonable style. You create an NSViewController
subclass for each tab, and assign it to the 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
defined as
-init{
self=[super initWithNibName:@"tabA" bundle:nil];
if(self){
...
}
return self;
}
Note that you don't need the extension .nib
when you call initWithNibName:bundle:
. And you should not specify the hard-coded path of the app. In iOS, the app's position is a given by the OS (with cryptic folder names,) but on OS X a user can freely move the app bundle to anywhere he wants. So, never refer to the main bundle as [NSBundle bundleWithPath:@"hard coded path"]
. Use just [NSBundle mainBundle]
, or just nil
in most cases. It's written in the documentation when you can just use nil
.
这篇关于Cocoa NSTabView编码风格问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!