How to hook up the window of MainWindow.xib with the AppDelegate in Xcode 4.2? - iphone

I am experimenting with Interface Builder in Xcode 4.2 and iOS 5 on a old Mac.
In Xcode 3.2 there was always a MainWindow.xib file and it contained not only the File's Owner which was UIApplication IMHO, but also an App Delegate placeholder object.
I created a MainWindow.xib file using the Window xib template. The AppDelegate placeholder is missing, so I can't hook the window up to my actual app delegate object.
I suppose that I will need to add a placeholder object with it's class identity set to "AppDelegate" but couldn't figure out how.

Just drag out one of the blue cubes (called "Object") from the objects library and change its class to the class of your app delegate.

Related

How to choose a nib as a start up interface for Mac OS X application

I'm new to macOS programming and recently I started working on this project. Because I needed to share my ViewController and view with my Safari extension target, I ended up setting the view controller manually in AppDelegate:
let application = NSApplication.shared()
let initVC = ViewController.viewControllerWithNib()
let window = application.windows.first!
window.windowController?.contentViewController = initVC
window.contentViewController = initVC
window.makeKeyAndOrderFront(nil)
I just left Main.storyboard to include the application portion since I couldn't figure out how to remove the storyboard and just use a xib as a startup for my application. Curently, I'm getting the following warning:
Window Controller requires a content view controller, main.storyboard
I'm trying to figure out why the app is giving that warning and what's the way to get rid of it.
You should see the info.plist, I remember there is a need to delete the name NSMainxxxx.
As Diven mentioned, there's also an entry in plist file, UIMainStoryboardFile which tells which storyboard needs to be used. The equivalent of it for nibs is NSMainNibFile. But in addition to that, there were several other steps that I needed to do for replacing the storyboard fully with a nib which are mentioned in this post. Generally, what you need is following steps:
Add a new nib to your project and choose a name, e.i. MainNib. You can choose an Application nib template
Go to project, under target -> General -> Deployment Info -> choose the nib you created as Main interface
Go to your nib, as mentioned in here, add a blue object and assign its class to AppDelegate and then ctrl+drag/drop from File owner to that object and choose that one to be the delegate.
I updated the project with these changes.
There's no more Info.plist you can easily select the target and check the Info tab. And there's Main nib file base name there.

Need help in Xcode with "ViewController"

I'm new to Xcode programming and I've been watching a couple videos here and there but one thing I never find on mine which the videos have. They have a file called "ViewController" (.h/.m). I don't have that, instead I have AppDelegate, RootView, DataView, and ModelController (all are .h/.m)
Choose the Single View Application template that contains ViewController. Or press command+N to create a new Cocoa Touch Class and make it subclass of UIViewController.

Delete storyboard xcode 4.2 iOS 5?

I created a project in xcode 4.2 using the feature of storyboard. I have done most of the work but now i came to know that storyboards are not available in pre-iOS 5 devices. Is there any way to remove this storyboard from the project without creating a new project? I don't want to do all the work again... any suggestions?
Delete the "Main Storyboard base name" in your Info.plist file and add a "Main nib" name (what was MainWindow in standard templates) or supply your app delegate class name to UIApplicationMain() in main.m

Proper setup for universal OpenGL ES iPhone/iPad app in XCode 4

I've been trying all morning to setup a univeral OpenGL-ES app with limited success. I can easily get the default OpenGL template app to compile for both devices and run just fine by adding a new XIB file and setting the proper values in it. Where I'm having trouble is figuring out how to give each device it's own unique GUI. Currently both devices use the same ViewController.xib file that is created with the project. How can I create a separate XIB file that uses the same ViewController .h and .m files? Do I need to create a separate AppDelegate class for each device type, or can they be shared?
The standard approach is to have a base AppDelegate class, and then subclass this for each device. Each delegate would then load its own XIB file with the correctly sized UIWindow and add the views.

What are the differences between Xcode generated .nib/.xib and interface builder .nib/.xib template?

I am new to iPhone development so I have been working through some tutorials. What I don't understand is how xib fit into the work flow.
In a tutorial, one of the instruction is to create a new UIViewController subclass with "XIB for User Interface" selected. On my first try, I neglected to check that option and I thought may be I can just create the xib in Interface Builder but that didn't work. ( I created the xib using Cocoa Touch View Template, with the same name as the UIViewController and saved it the into project directory so it was added to the project.) I even changed the Class Identify for the File's Owner and hooked up the view outlet (the two differences I noticed when I inspected the xib generated from Xcode.)
So what are the differences between Xcode generated .xib (from UIViewController Template) and the IB .xib template?
XIB files created as part of the New File flow in Xcode have their File's Owner class pre-set, as well as certain outlets (view) already connected. Otherwise, there's not much difference.
The XIB File is basicly an uncompile NIB File, XIBs can always be edited in Xcode (unless they are outdated or corrupt) but most NIBs are compressed (flat) and are unopenable. However the older NIBs are bundles containing some source/archived including designable.nib which is often just the renamed XIB File and a keyedobjects.nib which is an other compiled NIB
NIB = Nxt Interface Builder
XIB = Xml Interface Builder
Although the new archived NIB files are unopenable to most applications including Xcode, they can still potentially be unarchived. I found this freeware application called NibUnlocker On The CharlesSoft Website which can potentially disassemble a compressed Nib file and exports it as an XIB document. This application is still fairly buggy but it is sometimes very accurate based on the Nibs contents.
(NibUnlocker is a very inaccurate name, Nibs are not locked they are archived)
Click to Download Nib Unlocker
If You wish to know a bit more you can read some additional information I have provided below in regards to the NIB and XIB Formats:
Nxt Interface Builder Anatomy:
Archived NIBs
A Compressed NIB file is complicated file to analyse but this is not impossible. The structure of these files are based off of a compacted property list (begins with "bplist00") and some of its contents are archived through NSKeyedArchiver. Since a NIB is formatted as a property list, This allows a small hack: if you actually change the extension of a Nib to .plist, eg. ArchivedNib.nib to ArchivedNib.plist You will actually be able to open it in Xcode viewing it as a Property List. When you view a Nib as a property list you will probably get a few base properties such as $version, $objects, $archiver and $top.
Useful Notes
A CFKeyedArchiverUID object is actually a redirector, in the {value = xx}, the value is an offset for a item in the $objects array from the start of the array. eg. <CFKeyedArchiverUID 0x60800002bc20 [0x7fffef6b8c30]>{value = 29}, value = 29, the result would be the 29th item in the $object's array. In Objective C you can retrieve this value from an NSArray with this method :
+ (NSUInteger)valueForKeyedArchiverUID:(id)keyedArchiverUID {
void *uid = (__bridge void*)keyedArchiverUID;
NSUInteger *valuePtr = uid+16;
return *valuePtr;}
like if this helped ;-)
I'm not sure I'm following your question. When you created a xib file in Xcode, attempting to edit the xib file will bring up IB. So effectively you are using IB to edit the xib file in Xcode. I never tried creating a "stand-alone" xib file in IB and then hook it up to a project in xcode.
The only reason such an approach may not work is that when you create the xib file within the context of a project, there are associations created (such as "mainnib file base name" attribute in the plist) which will not be automatically generated when you attempt to use a standalone xib file with the xcode project.
It sounds like you configured the view xib properly, by setting the View outlet and configuring the custom class for File's Owner, but perhaps the problem was with the UIViewController subclass.
If your view controller subclass had implemented the -[UIViewController loadView] method directly, it'd prevent the NIB from loading. In the default implementation, the UIViewController will load the NIB file with the same name as the view controller. If you override this method to initialize the view a different way (e.g. completely programmatically), the default implementation that loads the NIB won't run.
Deleting an override of the -[UIViewController loadView] method in your subclass, or ensuring the names match, might resolve any discrepancies.
XIBs are XML. Diff them and find out for yourself.