Cocoa NSTabView编码风格问题

发布于 2024-09-11 06:07:06 字数 628 浏览 3 评论 0原文

我有一个编码风格问题,可能应该向工作中的高级 mac 程序员询问 - 但由于我是唯一的 mac 程序员,所以,确实如此。我的软件有一个弹出式 GUI(3D 模型、数据可视化),弹出式窗口主要是一个选项卡式控件,每个选项卡中都有大量内容(滑块、单选按钮、复选框等),大约有 20 个每个选项卡都有一个控件,也许还有六个选项卡...对所有视图使用单个控制器很快就会变得笨拙。

有一个加载一堆选项卡的 MainViewController 是好的风格吗?

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"]];

我在 iOS 上就是这样做的,但我不确定 Mac OS X 上的做法。我更喜欢提供可维护性和灵活性的风格,因为代码正在经历原型设计,我可能需要经常更改它。

如果这都不是好的风格,那什么才是呢?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2024-09-18 06:07:06

我认为你的风格是合理的。您为每个选项卡创建一个 NSViewController 子类,并使用 NSTabViewItem 将其分配给 NSTabView

顺便说一句,我认为最好将

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

@interface TabAController:NSViewController ... @endinit 定义为

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

请注意,您不需要扩展 .nib 当您调用 initWithNibName:bundle: 时。并且您不应指定应用程序的硬编码路径。在 iOS 中,应用程序的位置是由操作系统给定的(具有神秘的文件夹名称),但在 OS X 上,用户可以自由地将应用程序包移动到他想要的任何位置。因此,切勿将主包称为 [NSBundle bundleWithPath:@"hard coded path"]。在大多数情况下,仅使用[NSBundle mainBundle],或仅使用nil。当你可以只使用nil时,文档中写了它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文