What is the equivalent to UIViewController methodology for OSX? - macos

I am new to OSX development.
Before storyboards on iOS, when you created a single view application, you would end with this structure:
AppDelegate.h
AppDelegate.h
ViewController.h
ViewController.m
ViewController.xib
The app would start on the delegate and call the xib and its classes, so the entry point to the app would be viewDidLoad inside ViewController.m
I have created an app for OSX. All I have is
AppDelegate.h
AppDelegate.m
MainMenu.xib
I would now to recreate something like the ViewController.h and ViewController.m and transfer control to something like a viewDidLoad, but I see this MainMenu.xib of cocoa has a window inside.
What do I do? Create a custom class for this window? I did not see any equivalent to viewDidLoad, viewDidAppear, etc. What is the equivalent for NSWindow or if this is now how it is done, please tell me.

The AppDelegate should have a applicationDidFinishLaunching which you can use as the entry point. the AppDelegate has a window associated with it by default. You can use AppDelegate to create the various features you would like to use. An alternative is to create a subclass of NSWindowController and have an associated xib for that which you can load when you want. Hope this helps.

Related

confused about create an IPAD application. change to a UISplitView after logined from UIView using storyboard

I am having an project that required to login, and I am using a Single view application to create the app, so the first page should be a UIView.
After login the page, I decide to change the view to a SplitView which contain a tableview on the left and a view on the right.
when i using storyboard, i create the splitViewController. so, do i need to create a splitViewController .h and .m to handle it?
reason to asking this question is because, when i create a new project using Master-Detail Application and it only contain a MasterViewController .h, .m (tableview) and DetailViewController .h, .m (UIview).
also, may i know how to change the view to a UISplitView when i only got MasterViewController .h, .m (tableview) and DetailViewController .h, .m (UIview)?

How do you create and attach MainMenu.xib manually in Cocoa Application?

I already started working on a few small Cocoa Application. It works just fine, but now I want to create my own MainMenu (not using the default MainMenu.xib created by XCode).
But I got a few obstacle. First, I add two XIB and its corresponding NSWindowController. The idea is the first xib will call the other xib file. But as these two xib file is a Window and with its NSWindowController, I got quite confuse on how to add the MainMenu. I create another XIB file with name MainMenu.xib, and in the startup XIB file, I do this :
- (void)windowDidLoad
{
[super windowDidLoad];
mainMenu = [[NSMenu alloc] initWithWindowNibName:#"MainMenu"];
[self setMainMenu:mainMenu];
}
but it's not working. The first startup XIB didn't display the MainMenu at all (so I can't quit the application).
As for the MainMenu.xib itself, I already connect it with the startup XIB (using NSOBject that dragged into left pane of the XIB Designer).
What is the proper way of creating main menu for multi XIB like this?
I hope I state my problem correctly, as I quite new in this Cocoa things :)
Thanks in advance!
You don't have to create another xib to change the main menu bar.
You just edit the menu bar inside the MainMenu.xib in the interface builder, that's it!

Changing app to use a Tab Bar controller

I'm creating my first iPhone application (using XCode 4), and I initially created the project using the Navigation based application template. I've since decided that I want the UI to have a Tab Bar down the bottom with a Navigation Bar up the top, but am having difficulty changing my app to do that.
I added a new window to my app, and called it TabWindow.xib. I opened this up in Interface Builder and added a Tab Bar Controller. I then added an outlet property for the controller into AppDelegate.h as follows:-
#property (nonatomic, retain) IBOutlet UITabBarController *tabController;
This was synthesized in AppDelegate.m with the following:-
#synthesize tabController=_tabController;
I then changed the code in applicationDidFinishLaunchingWithOptions to the following (to switch out the old view controller with my new one):-
//self.window.rootViewController = self.navigationController;
self.window.rootViewController = self.tabController;
When I run the application, instead of seeing the Tab Bar view as expected, I see an empty window. I suspect I need to (at the very least) connect to the tabController outlet I created above, but I can't figure out how to do this. And is there anything else I need to do to get this to work?
You need to add the connection to the app delegate in interface builder. To do this, add an "Object" from the Object library and change its class to your app delegate. Then add the connections in the connections inspector.
Also, in your applications info plist file, you might have to set "Main nib file base name" to the new xib name.

Xcode 4 and controllers with xibs

I have main xib with a splitview controller and ive dragged the ibactions and properties on to the AppDelegate code.
So in my applicationDidFinishLaunching i would like to load a controller which uses a xib into one of the nsviews that i have linked up.
The problem is that i can't use xcode to link ibactions and properties from the new xib into the controller that is going to load it.
Does that have to be done programatically?
I'm unsure of exactly what you are trying to do. However, it sounds like the 'splitview controller' you are referring to should be a subclass of NSViewController, then it can manage the xib for you.
Again, I'm not certain what you are trying to do; perhaps post a snippet of code?

How to use NSWindowController?

I'm looking in to using NSWindowController and I just can't think how to get it working. How do I start using it?
It's difficult to answer this question without knowing what you're trying to do. However, if you are writing a document-based application, an NSWindowController is automatically created for each window you create, so you don't need to create one specially.
The way I use NSWindowController is I create a different subclass for each type of window in my application. For example, I might have a 3D application with an AppWireframeWindowController and an AppPreviewWindowController. Each subclass automatically loads the correct nib file, and has code that hooks the document's data to the views in the nib.
If you are using storyboards you can connect an NSWindowController subclass up in IB. Otherwise if you are using nibs and have just the default template for a Mac Cocoa app then you may need to make it in code or just use a subclass of NSWindow.
Otherwise you can create a new NSWindowController and check the 'Also create XIB file for user interface' and it will give you the nib and also the NSWindowController subclass. It is basically a new nib where 'File's Owner' is your NSWindowController and the Window is the .window object inside the NSWindowController and the delegate is also pointed there.
You may be able to modify that.

Resources