I can guess what might be the problem here, because I've done it:
I've found that often when I add init code to loadView, I end up with an infinite stack trace
Don't read self.view in -loadView. Only set it, don't get it.
The self.view property accessor calls -loadView if the view isn't currently loaded. There's your infinite recursion.
The usual way to build the view programmatically in -loadView, as demonstrated in Apple's pre-Interface-Builder examples, is more like this:
UIView *view = [[UIView alloc] init...];
...
[view addSubview:whatever];
[view addSubview:whatever2];
...
self.view = view;
[view release];
And I don't blame you for not using IB. I've stuck with this method for all of Instapaper and find myself much more comfortable with it than dealing with IB's complexities, interface quirks, and unexpected behind-the-scenes behavior.
setValue:forKey:
is part of the NSKeyValueCoding protocol, which among other things, lets you access object properties from the likes of Interface Builder. setValue:forKey:
is implemented in classes other than NSDictionary
.
setObject:forKey:
is NSMutableDictionary's
reason to exist. Its signature happens to be quite similar to setValue:forKey:, but is more generic (e.g. any key type). It's somewhat of a coincidence that the signatures are so similar.
What adds to the confusion is that NSMutableDictionary's implementation of setValue:forKey:
is equivalent to setObject:forKey:
in most cases. In other classes, setValue:forKey:
changes member variables. In NSMutableDictionary
, it changes dictionary entries, unless you prefix the key with a '@' character -- in which case it modifies member variables.
So, in a nutshell, use setObject:forKey:
when you need to work with dictionary keys and values, and setValue:forKey:
in the rarer cases where you need to tackle KVP.
EDIT: and oh, it looks like this has been asked and answered before: Difference between objectForKey and valueForKey?
Best Solution
initWithNibName
- is what you call to create a view controller from specified nib file.viewDidLoad
- is what system calls on your controller after the controller’s view is loaded into memory. You can implement this method to perform some additional initialization (which is not done in nib file)