+2  A: 

initWithStyle is not the same as initWithCoder. Your constructor probably isn't even getting called.

Marc W
+1  A: 

Well, if you are initializing this controller using initWithStyle and you previously were calling initWithCoder , that is your problem.

You are loading your self.jokes in initWithCoder. You should move that code to viewDidLoad or to your new initWithStyle method

// move this
self.jokes = [NSMutableArray arrayWithObjects:
                                  [Joke jokeWithValue:@"If you have five dollars and Chuck Norris has five dollars, Chuck Norris has more money than you"],
                                  [Joke jokeWithValue:@"There is no 'ctrl' button on Chuck Norris's computer. Chuck Norris is always in control."],
                                  [Joke jokeWithValue:@"Apple pays Chuck Norris 99 cents every time he listens to a song."],
                                  [Joke jokeWithValue:@"Chuck Norris can sneeze with his eyes open."],
                                  nil];
Jab
I changed the code and init'd it in the initWithStyle. Still same problem though
Daniel Kindler
You need to show the code that initializes this controller, from what is shown I can't see how this code is being called.
Jab
+2  A: 

I don't know if it's the cause of your problem, but that random [jokeTableView init] in awakeFromNib is certainly wrong and could cause problems like this. init should never be called without an attached alloc*, and in this case I doubt either is needed since the table view has presumably already been created elsewhere.

(* The one exception to this rule, obviously, is when you're overriding an init method and calling super.)

Chuck
I agree, the TableView shouldn't have to be initialized every time it becomes visible. I also don't think this is an issue with populating the data, as you would at least see blank TableViewCells.
mgriepentrog
A: 

Get rid of this:

- (void)awakeFromNib {
[jokeTableView init];
}

you're already doing initialization in initWithStyle:

stefanB
that worked. But why wont my jokes populate it?
Daniel Kindler
A: 

I think the main problem is that you need to replace:

- (id)initWithStyle:(UITableViewStyle)style {
    if (self = [super initWithStyle:style]) {

(and the closing bracket)

with

- (void)viewDidLoad {

Also, you shouldn't have to end a NSMutableArray with nil.

jmans
You need to end NSMutableArray with nil see http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
stefanB
The other part does not seem right either, viewDidLoad is called each time a view is unarchived from xib (if it is stored in xib) so you would reiinitialize the jokes everytime which is not what you want. View can get unloaded (by controller?) when memory is low and reloaded later on, I think viewDidLoad will get called each time.
stefanB
@stefan your right. But I did what you said, and now the TV is shown, but it wont populate... Whats wrong?
Daniel Kindler
You're right about NSMutableArray--I have always used addObject to populate my arrays, which won't accept nil. The issue with reinitializing the array every time viewDidLoad is called can be dealt with my checking for any content in self.jokes first.
jmans
+2  A: 

If your view controller is being loaded from a nib, you'll need to override the initWithCoder: method, not initWithStyle:.

However, the normal solution would be to add all your custom initialization code in the awakeFromNib: method, this is called after the nib is loaded and all outlets are connected, so it makes a great place to do any initialization you need.

See the Apple docs on awakeFromNib: for details on object instantiation from nibs. Also, if you have access to the 3.0 beta docs, do a search for awakeFromNib:, the updated wording gives a better explanation of which methods are called and when.

P.S. You shouldn't be calling [jokeTableView init] in your code, this will be done automatically when the nib is unpacked.

Edit: Since you are setting properties for your table view from your initialization code, this should definitely be in awakeFromNib:, not initWithCoder: or initWithStyle:.

Looking at the screenshot, you might also want to make sure with Interface Builder that the UITableView is placed correctly in the nib file for your view controller, and that the code (or nib) that creates your view controller is referring to the right nib file - if it were just the data for the table view that had not loaded, you would see gray lines between empty cells, not just blank white space like in that image.

Tobias Cohen