Reputation: 1287
I have following code in a subclass of UITableViewController. Under iOS 5.1 it works fine, but under iOS 6, self.tableView is nil (both in simulator and on real device). Am I doing it wrong? Why isn't the view set straight away after the init?
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self)
{
UIView * bck = [[UIView alloc] init];
[bck setBackgroundColor:[UIColor whiteColor]];
self.tableView.backgroundView = bck;
[bck release];
}
return self;
}
EDIT:
I've nailed down the problem:
I've got class
AccountsListViewController_iPad
which is subclass of
AccountsListViewController : UITableViewController
AccountsListViewController has it's tableView & view loaded after init (as I would expect). AccountsListViewController_iPad on the other hand has it's view and tableView equal to nil. I've removed everything from AccountsListViewController_iPad so now it looks as follows:
.h
#import <UIKit/UIKit.h>
#import "AccountsListViewController.h"
@interface AccountsListViewController_iPad : AccountsListViewController
@end
.m
#import "AccountsListViewController_iPad.h"
@implementation AccountsListViewController_iPad
@end
And still it's view is nil. In my opinion, it should behave exactly the same as its superclass, but it doesn't.
Upvotes: 2
Views: 1435
Reputation: 1287
Alright, I've worked it out:
There was AccountsListViewController_iPad class and associated AccountsListViewController_iPad.xib file. Xib, despite not being loaded anywhere in the code and file owner in xib not being AccountsListViewController_iPad, was still being loaded. For some reason, the table view in xib was set to property 'table' in file owner (which didn't exist) and hence view and tableView were nil.
I still don't know why the xib was loaded or why it issue exist happen under iOS 5.x
Upvotes: 2
Reputation: 11920
I suspect this is because the table view is not load until the view is loaded. You should move the view setup to viewDidLoad
.
The only 'view' property you should set up in init
methods is .navigationItem
(although I think UINavigationItem
is probably best considered part of the controller rather than view).
Upvotes: 3