views:

24

answers:

1

I have a TabBar App. I have created a UITableView class called "Schedule" that has a matching Nib. I want to add Schedule to the TabBar, but I do not want to do it through Interface Builder. When I add it Programmatically, I see the TableView, but it is blank. I have added some NSLogs to Schedule.m and the class does not appear to be called. The Nib and the Schedule Class are connected properly. I figure I am doing something wrong in the code where I am adding the UITableView to the TabBar:

// Create View Controllers
UITableViewController *scheduleViewController = [[UITableViewController alloc] initWithNibName:@"Schedule" bundle:nil]; 

// Create UITabBarItems
UITabBarItem *scheduleTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Schedule" image:[UIImage imageNamed:@"calendar.png"] tag:0];

scheduleViewController.tabBarItem = scheduleTabBarItem; 

// Create Array of View Controllers
NSArray *items = [NSArray arrayWithObjects:scheduleNavigationController, nil];

// Add View Controllers to TabBar
[tabBarController setViewControllers:items animated:NO];    

// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
A: 

You are instantiating a UITableViewController, which does not contain any code to fill the table view with data. So where do you suppose the data for the table should come from? If you have written a custom UITableViewController subclass for it, you have to instantiate this subclass here (and set it as the File's Owner in your NIB file).

Ole Begemann
It is set as the file's owner in the Nib... I thought that would be enough to tell it where to get the data from.
Chris
Thank you , that was the kick in the brain I needed. I changed it to be Schedule *scheduleViewController = [[Schedule alloc] initWithNib:@"Schedule" bundle:nil];
Chris