Cocoa NSTabView编码风格问题
我有一个编码风格问题,可能应该向工作中的高级 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的风格是合理的。您为每个选项卡创建一个
NSViewController
子类,并使用NSTabViewItem
将其分配给NSTabView
。顺便说一句,我认为最好将
@interface TabAController:NSViewController ... @end
与init
定义为请注意,您不需要扩展
.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 theNSTabView
usingNSTabViewItem
.By the way, I think it's better to have
with
@interface TabAController:NSViewController ... @end
withinit
defined asNote that you don't need the extension
.nib
when you callinitWithNibName: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 justnil
in most cases. It's written in the documentation when you can just usenil
.