Mac OS X 上的 Cocoa 应用程序架构

发布于 2024-08-03 06:12:31 字数 968 浏览 8 评论 0原文

在长期从事 iPhone 工作后,我将重新开始在 Mac 上进行 Cocoa 开发。我之前在 Mac 上使用 Cocoa 的经历只是一些很小的工具。我正在寻求建立一些严肃的东西。

看看像 iPhoto(或 Mail 或 Things 或......)这样的现代 Cocoa 应用程序,许多应用程序都使用单窗口、基于源列表的方法。我正在尽我所能地思考这一点,因为它似乎提供了良好的体验。不过,我遇到了一点麻烦。我认为它应该是这样的,但我想知道其他人是如何做到的,以及真正最好的方法是什么:

  • 应用程序的起点是一个 AppDelegate 对象,启动后,它创建一个 Window[Controller?]从笔尖,并设置其数据(例如,从 CoreData)

  • WindowController 加载一个本质上只有一个 NSSplitView 的窗口。

  • splitview 的左侧有一个 NSTableView 或 NSOutlineView,设置为具有 SourceList 样式。

    splitview
  • 右侧有应用程序的主要内容,具体取决于选择了表格视图的哪个项目。

    右侧有应用程序的主要内容,具体

我会假设某个地方(哪里?)有 NSViewController 管理将出现在右侧的每个不同视图(想想 iPhoto 如何拥有所有照片、事件、面孔、地点等,我想它们都可能出现在不同的笔尖中...这是正确的吗?)。

这些视图控制器可能绑定到左侧的源列表。它是如何工作的(源列表可能由 NSViewController 的 NSArrayController 支持?)。

无论如何,这些是我的想法,我完全偏离基地还是......?我浏览了网络,发现这篇文章这里,我看过一些苹果源代码,但我似乎无法理解它。欢迎任何指导。

I'm getting back in to Cocoa development on the Mac after a long stint doing iPhone work. My previous experience with Cocoa on the Mac has just been dinky little tools. I'm looking to build something serious.

Looking at a modern Cocoa application like iPhoto (or Mail or Things or....) many apps use the Single-Window, Source-List based approach. I'm trying to wrap my head around that as best I can because it seems to provide a good experience. However, I'm having a little trouble. Here's how I think it should look, but I'm wondering how others are doing it, and what's really the best way:

  • Starting point of the app is an AppDelegate object which, after launching, creates a Window[Controller?] from a nib, along with setting up its data (from, say CoreData)

  • WindowController loads a window which essentially just has an NSSplitView in it.

  • Left side of the splitview has an NSTableView or NSOutlineView which is set to have the SourceList style.

  • Right side has the main content of the app, depending on which item of the table view is selected.

I would assume somewhere (where?) there are NSViewControllers managing each of the different views which will appear in the right side (think how iPhoto has All Photos, Events, Faces, Places, etc. and I imagine they could all appear in different nibs... is this correct?).

Those view controllers are probably bound to the source list on the left.. how does that work (source list is backed by an NSArrayController of NSViewControllers maybe?).

Anyway, those are my thoughts, am I completely off-base or...? I've looked around the web, found this post here, and I've looked at some Apple source code but I can't seem to wrap my head around it. Any guidance would be welcome.

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

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

发布评论

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

评论(2

半世蒼涼 2024-08-10 06:12:31

如果您要将某些视图替换为其他视图,则将视图分解为单独的笔尖主要是有好处的,因为您可以延迟加载它们。是的,在现代应用程序中,您可以使用 NSViewController,或者可能使用 KTUIKit 中的 KTViewController(请参阅< a href="http://katidev.com/blog/2008/04/09/nsviewcontroller-the-new-c-in-mvc-pt-1-of-3/" rel="nofollow noreferrer">帖子她与人合写了 NSViewController)

但是,不要只是投入源列表的怀抱。单窗口界面对于简单的应用程序来说可能很有用,但当你有很多事情发生时,它很快就会变得笨拙,因为通过将它们分成单独的窗口可能会更好地服务它们; iTunes 和 Xcode 都提供了许多这方面的示例(尤其是后者,因为您可以在 SWI 和 MWI 之间切换)。

您需要考虑多窗口界面还是单窗口界面更适合您的应用程序。没有一个答案可以适用于所有应用程序;这完全取决于您的应用程序、您想要它做什么以及您想要它的外观 - 您(加上团队的其他成员,如果有的话)是唯一可以回答这个问题的人。您可能需要进行一些纸质原型设计,以便在每个方向上进行快速实验,以便您至少可以将两个 UI 的虚假示例进行对比。

Breaking the views up into separate nibs is mainly good if you're going to swap out some views for others, since you can load them lazily. And yes, in a modern app, you would use NSViewController, or perhaps KTViewController from KTUIKit (see the posts she co-wrote about NSViewController)

Don't just go running into the arms of the source list, however. A single-window interface can be good for simple apps, but it can quickly become unwieldy when you have many things going on, as they may be better served by breaking them into separate windows; iTunes and Xcode both provide many examples of this (especially the latter, since you can switch it between SWI and MWI).

You need to think about whether a multiple-window or single-window interface would be better for your app. There is no one answer for all apps; it depends entirely on your app, and what you want it to do, and how you want it to look—you (plus the rest of your team, if you have one) are the only one who can answer this question. You may want to do some paper prototyping to do quick experiments in each direction so that you can hold at least fake examples of both UIs up against each other.

雨后彩虹 2024-08-10 06:12:31

了解笔尖分割方式的一种简单方法是进入 iPhoto 目录并开始打开笔尖。

如果您想进一步探索类结构,您可以尝试使用 F 脚本

One easy way to get a feel for the way nibs are split up is to just go into the iPhoto directory and start opening up nibs

If you want to explore a little more into the class structure you can try browsing around using F-Script

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