I currently have a tab bar application in the works, and have run into a bit of a roadblock. No data is populated in the table view, When i try to load my TableViewController with records from an NSMutable array.
RootViewController methods – which is the TableViewController
- (id)init
{
//Call the superclass's designated initalizer
self = [super initWithNibName:nil bundle:nil];
if (self){
//Populate NSMutalableArry with all pub objects
for(int i=0; i<10; i++){
[[PubStore defaultStore] createPub];
//j = [[[[PubStore defaultStore] allPubs] objectAtIndex:i] getPubName];
}
//Get the tab bar item
UITabBarItem *tbi = [self tabBarItem];
//Give it a label
[tbi setTitle:@"Pubs"];
//Create a UIImage from a file
UIImage *i = [UIImage imageNamed:@"88-beermug.png"];
//Put Image on the tab bar item
[tbi setImage:i];
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[PubStore defaultStore] allPubs] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create an instnce of UITableViewCell, with default appearance
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
//Set the text on the cell with the description of the possession
//that is at the nth index of the possessions, where n =row this cell
//will appear in on the tableview
Pub *p = [[[PubStore defaultStore] allPubs] objectAtIndex:[indexPath row]];
NSLog(@"Display Pub Name: %@", [p getPubName]);
[[cell textLabel] setText: [p getPubName]];
return cell;
}
PubStore Methods
- (id)init
{
if (defaultStore) {
//Return the old Default Store
return defaultStore;
}
self = [super init];
if(self){
allPubs = [[NSMutableArray alloc] init];
}
return self;
}
- (NSArray *)allPubs
{
return allPubs;
}
- (Pub *)createPub
{
//* random possessions does not exist in my Pub Class
Pub *p = [Pub randomPub];
NSLog(@"New Pub: %@", p);
[allPubs addObject:p];
return p;
}
Any help you could provide me would be greatly appreciated, i’m in the progress of learning objective c and this is one roadblock that i need to get passed.
I found the source of the issue. I was returning 0 instead of 1 in the
numberOfSectionsInTableView:method. I mistakenly modified this method, and doing so was telling the program that there are no row sections to populate.Incorrect Method
Correct Method