Reputation: 415
Here's the basic code (based on Xcode's Tabbed Applicaion Template)
ViewController.h
@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic,retain) NSMutableArray *movies;
@property (nonatomic,retain) IBOutlet UITableView *tableView;
ViewController.m
@implementation ViewController
@synthesize movies,tableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Watchlist", @"Watchlist");
self.tabBarItem.image = [UIImage imageNamed:@"watchlist"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"tableView = %@", tableView);
}
Output
tableView = (null)
The TableView is connected to File's owner in IB with class is set to ViewController
I really don't get why the tableView is null. I'm not a complete newbie to Cocoa (but to the iPhone SDK), I created a Single View based Application with a TableView dataSource to see if I was missing something. I got it working in under a minute.
Anybody can help out?
Upvotes: 3
Views: 8176
Reputation: 9579
Make sure the nib/xib is included in your current target.
I just experienced this issue on Xcode5 with iOS7 SDK. Strangely enough, I discovered that the nib wasn't included in my target anymore. I don't know when and why that happened, but it had this strange side effect that most IBOutlets weren't set up properly, even if all connections from code to nib/xib were fine.
For example: my MKMapView *map
was in my list of subviews on viewDidLoad:
, but the IBOutlet MKMapView *map
property in my view controller was still nil. After I ticked the "include in target" checkbox, everything worked as expected.
Upvotes: 1
Reputation: 38728
In interface builder right click File's Owner
and ensure that the following connections are made:
Outlets
tableView - Table View
Referencing Outlets
dateSource - Table View
delegate - Table View
I suspect you may have not made the first connection?
Upvotes: 8