且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有Interface Builder的情况下创建Cocoa接口?

更新时间:2022-04-11 00:20:54


我喜欢以编程方式创建我的界面。 / p>

I would prefer to create my interfaces programatically.

为什么? Interface Builder更容易,更快。你不能通过拖放来写错字,当你用手打字矩形时,你不会得到那些非常方便的Aqua指南。

Why? Interface Builder is easier and faster. You can't write a typo by drag and drop, and you don't get those oh-so-handy Aqua guides when you're typing rectangles by hand.

不要打它。 Interface Builder是您的朋友。让它帮助你。

Don't fight it. Interface Builder is your friend. Let it help you.

如果你坚持通过在代码中编写你的UI浪费你自己的时间和精力:

If you insist on wasting your own time and energy by writing your UI in code:

不是基于文档的(通常基于库的,如邮件,iTunes,iPhoto):创建NSObject的子类,实例化它,并将其作为应用程序的委托,并在委托的 applicationDidFinishLaunching:方法,创建一个窗口,用视图填充它,然后排序。

Not document-based (generally library-based, like Mail, iTunes, iPhoto): Create a subclass of NSObject, instantiate it, and make it the application's delegate, and in the delegate's applicationDidFinishLaunching: method, create a window, populate it with views, and order it front.

基于文档Preview,QuickTime Player):在NSDocument子类中的 makeWindowControllers 方法中,创建你的窗口(并用视图填充它们)并为它们创建窗口控制器,确保发送 addWindowController:

Document-based (like TextEdit, Preview, QuickTime Player): In the makeWindowControllers method in your subclass of NSDocument, create your windows (and populate them with views) and create window controllers for them, making sure to send yourself addWindowController: for each window controller.