Issues & Solutions for getting started in iPhone Projects

In the course of doing recipes for the Erica/Alexis project, I have learned that there are several things I need to be sure to do before modifying any of the base templates Apple provides.

1. Remember to add the app delegate string to main

When starting a new project, I am often faced with a black screen.  Despite the fact that this has happened to me three times now, it still takes me a bit of hair tearing before I remember it’s because I need to add the app delegate to the fourth parameter in the main method.

The solution to this, of course, would be to update my user templates so I don’t have to remember to do this every time.

2. Set the file’s owner to be the view controller

By default, the File Owner’s type is set to NSObject. When I have ViewControllers I want to use as a basis for my project, I need to change this so the File Owner’s type is set to my custom Root ViewController.

3. Remove the main xib line from info.plist

After changing (1) and (2), I was still getting this error: “2010-05-07 15:12:55.632 TwoItems[21829:207] Failed to load NSMainNibFile MainWindow.”

The problem was in the info.plist file. There is an attribute called “Main nib file base name.” Erica directs her audience to delete this line, and update a class template to not include this line in the info.plist going forward!

4. Change the applicationDidFinishLaunching method
define (void)applicationDidFinishLaunching:(UIApplication *) application

By default, Apple’s SplitViewController base template will use didFinishLaunchingWithOptions, which returns a BOOL. Instead, Erica uses applicationDidFinishLaunching throughout the book, which returns void.

5. CHECK FOR WARNINGS in IB!!

Finally, if you have any items in Interface Builder, make sure they are not producing any warnings! Unresolved warnings in IB will often lead to runtime crashes.

I was crashing with the following: 2010-05-09 17:53:21.422 ToDos-v1[31299:207] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key window.'

I needed to:

  1. take the App Delegate out of the xib file
  2. disconnect file owner’s delegate connector
  3. connect file owner’s view to the view

The lesson here? BUILD YOUR OWN CUSTOM XCODE TEMPLATES.

blog comments powered by Disqus

LouiseBrooks theme byThemocracy