I’ve been converting a simple program that uses a xib file to be done programatically. I’ve removed the elements one by one and put them back in in the code.
Can I eventually delete the entire file? or is it used for something vital?
There seem to be three.
PhoneContent.xib
MyView.xib
MainWindow.xib
You don’t need the MyView.xib or PhoneContent.xib so you can just delete them if you’ve recreated the layouts in code.
To remove MainWindow.xib, you will need to update the application:didFinishLaunchingWithOptions method to set up the window and main view controller programmatically, but more subtly than that you’ll need to modify the main function in main.m
Instead of looking like this:
You’ll need it to look like this:
You’ll also have to delete the reference to MainWindow (Main nib file base name) from your info.plist file.
Okay. So now I’ve told you how to delete your nib files, do you mind if I ask why you are doing it? Generating layouts in code is madness! It’s like trying to generate HTML in JavaScript, or generate a picture by specifying the colors as hexadecimal numbers ina text file.
You’re taking an interface which is easy to tweak visually without needing to compile and run each time you move something a few pixels, and making it much harder to maintain.
You’re taking layout code that is guaranteed to be bug free because it is generated automatically, and replacing it with loads of hand-written code that could be full of memory leaks or conceptual errors.
What have you got against nib files?