高级应用程序设计/架构
在过去的几年中,我完成了大量的 iOS 开发,因此我非常熟悉 iOS 架构和应用程序设计(一切都是一个 ViewController,您可以将其推送、弹出或粘贴到选项卡栏中)。我最近开始探索正确的 Mac 应用程序开发,但感到有点迷失。我真的只想进行一次健全性检查,也许还有一些关于构建这样的应用程序的正确方法的建议:
我想构建一个库式的单窗口应用程序,它将在运行期间生成额外的窗口它的操作,但不如完整的文档。主窗口的布局与 OS X Lion 的 Mail.app 非常相似,具有三宽分割视图,其中包含:
- 源列表,或高级主题选择
- 列表视图
- 详细信息视图,显示中间窗格中所选对象的详细信息
正如我所说,就外观而言与 Mail.app 非常相似去。
我的问题实际上是如何从 XCode 内部将所有这些粘合在一起。到目前为止,我的困惑在于:
默认项目生成了一个带有主菜单和窗口的 NIB。我喜欢封装功能,所以我应该为此窗口创建一个窗口控制器并以某种方式将其连接到 Interface Builder 中,还是特定于窗口的功能属于其他地方?
如果可能的话,我希望三个窗格中的每一个都是单独的视图控制器。我创建了三个 NSViewController 子类(XCode 自动生成 NIB),并添加(到主菜单/窗口 NIB)指定每个类的视图控制器对象,将每个类的
view
属性连接到三个view 之一。 code>Custom View
通用 NSView 对象我放入 NSSplitView 中。当我尝试设置每个视图控制器的 NIB 时,只有主菜单/窗口 NIB 出现在下拉列表中,并且手动键入所需的 NIB 似乎没有效果(运行应用程序时视图的内容实际上并未出现) 。这让我觉得我做错了什么。我对前两个窗格应该使用什么类型的视图有点模糊。显然,我将为最终窗格构建一个自定义窗格,但似乎前两个窗格已经存在于 Cocoa 框架中。
无论如何,如果我做的事情完全错误,请不要费心解决我的问题;只是告诉我我应该做什么。我想我只需要一位合适的 Mac 开发人员来为我指明正确的方向。
I've done a fair amount of iOS development in the past couple of years, so I'm pretty familiar with iOS architecture and app design (everything's a ViewController that you either push, pop, or stick into tab bars). I've recently started exploring proper Mac app development and feel a little lost. I'd like to really just have a sanity check and maybe some advice as to what the proper way to build an app like this is:
I'd like to build a library-style, single window app, that will spawn additional windows during its operation, but not as full-blown documents. The main window will be laid out much like OS X Lion's Mail.app, with a three-wide split view containing:
- A source list, or high-level topic selection
- A list view of items pertaining to the topic selected in the first pane
- A detail view, which shows the details of the object selected in the middle pane
Like I said, really similar to Mail.app as far as looks go.
My question is really how to glue all this together from inside XCode. Here's where my confusion lies so far:
The default project generated a NIB with a main menu and window. I like to encapsulate functionality, so should I make a window controller for this window and somehow hook it up in Interface Builder, or does window-specific functionality belong somewhere else?
If possible, I'd like each of my three panes to be separate view controllers. I created three NSViewController subclasses (XCode automatically generated NIBs), and added (to the main menu/window NIB) view controller objects with each class specified, hooking up each one's
view
property to one of the threeCustom View
generic NSView objects I dropped into the NSSplitView. When I tried to set each view controller's NIB, only the main menu/window NIB appeared in the drop-down, and typing the desired one by hand seemed to have no effect (the view's contents didn't actually appear when running the app). This makes me think I'm doing something wrong.I'm a little fuzzy on what types of views I should use for each of the first two panes. I'll obviously build a custom one for the final pane, but it seems like the first two should be present in the Cocoa framework already.
Anyway, if I'm doing completely the wrong thing, don't bother addressing my questions; just tell me what I should be doing instead. I think I just need a proper Mac developer to point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于你的第一个问题,你不需要使用Apple在MainMenu.xib中提供的主窗口。如果需要,您可以从笔尖中删除该窗口,然后在
applicationDidFinishLaunching:
委托方法中实例化一个NSWindowController
,然后加载并控制主窗口。您肯定对 NSViewController 感到困惑,这并不奇怪,因为您可能认为它的工作方式与 UIViewController 类似。
事实上,
NSViewController
与UIViewController
完全不同,并且不具有相同级别的 Interface Builder 支持。例如,您不能将视图控制器放置在 IB 的窗口中,而这是 iOS 上的标准做法。NSViewController
是 Mac 上一个相对较新的类,通常使用它以编程方式加载视图并管理视图内容。在 Mac 上与
UIViewController
最接近的类是NSWindowController
。它的存在时间比NSViewController
要长得多,事实上,许多 Mac 应用根本不使用NSViewController
。一般来说,应用程序中的每个窗口都应该有一个窗口控制器来管理它。您可以使用 NSWindowController 的子类来处理每个窗口的许多功能。
如果您想使用 NSViewController,那么您应该使用窗口控制器来管理这些视图控制器对象。由于上述缺乏 Interface Builder 支持,这通常以编程方式完成。每个 NSViewController 实例从特定的 nib 文件加载其视图。您通常不会在 Interface Builder 中添加视图控制器。
对于源列表,如果您有多个部分,通常会使用
NSOutlineView
或NSTableView
。每当您需要项目列表时,就会使用这两个对象。NSOutlineView
是分层的,而NSTableView
是平面的。我希望这有帮助。
With regard to your first question, you don't need to use the main window that Apple supplies in MainMenu.xib. If you want, you are free to delete that window from the nib and then instantiate an
NSWindowController
in yourapplicationDidFinishLaunching:
delegate method which then loads and controls the main window.You are definitely confused about
NSViewController
, which is not really all that surprising, since you might assume that it works likeUIViewController
.In fact,
NSViewController
is completely different toUIViewController
and does not have the same level of Interface Builder support. You can't place a view controller in a window in IB, for example, whereas this is standard practice on iOS.NSViewController
is a relatively new class on the Mac and generally you use it to load views programmatically and manage the view content.The class that most closely maps to
UIViewController
on the Mac isNSWindowController
. This has been around a lot longer thanNSViewController
and in fact many Mac apps don't useNSViewController
at all.Generally, each window in your app should have a window controller managing it. You can use subclasses of
NSWindowController
to handle a lot of the functionality for each window.If you want to use
NSViewController
, then you should use your window controller to manage those view controller objects. This is generally done programmatically due to the aforesaid lack of Interface Builder support. EachNSViewController
instance loads its view from a specific nib file. You generally don't add view controllers in Interface Builder.For your source list you would generally use an
NSOutlineView
if you have multiple sections or anNSTableView
. These two objects are used whenever you need a list of items.NSOutlineView
is hierarchical, whereasNSTableView
is flat.I hope this helps.