I'm having an issue with my Master View controller
not appearing as specified by my storyboard.
By searching on this (awesome) site, I learned to check into my numberOfSectionsInTableView
and tableView:numberOfRowsInSection:
methods. I believe my issue is that tableView:numberOfRowsInSection:
is returning 'int 0'
.
Any help would be much appreciated.
My MasterViewController.m:
#import "ParentMasterViewController.h"
#import "ParentDetailViewController.h"
#import "NewEventDataController.h"
#import "NewEvent.h"
@interface ParentMasterViewController ()
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation ParentMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
self.dataController = [[NewEventDataController alloc] init];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataController countOfList];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
static NSDateFormatter *formatter = nil;
if (formatter == nil)
{
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // forIndexPath:indexPath];
// note: Add some code like this to create a new cell if there are none to reuse
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NewEvent *eventAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
[[cell textLabel] setText:eventAtIndex.event];
[[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)eventAtIndex.date]];
return cell;
}
In addition, my NewEventDataController.m:
#import "NewEventDataController.h"
#import "NewEvent.h"
@interface NewEventDataController ()
- (void)initializeDefaultDataList;
@end
@implementation NewEventDataController
- (void)initializeDefaultDataList
{
NSMutableArray *eventList = [[NSMutableArray alloc] init];
self.masterNewEventList = eventList;
NewEvent *event;
NSDate *today = [NSDate date];
event = [[NewEvent alloc] initWithName:@"Event" date:today];
[self addNewEventWithEvent:event];
}
- (void)setMasterNewEventList:(NSMutableArray *)newList
{
if (_masterNewEventList != newList)
_masterNewEventList = [newList mutableCopy];
}
- (id)init
{
if (self = [super init])
{
[self initializeDefaultDataList];
return self;
}
return nil;
}
- (NSUInteger)countOfList
{
return [self.masterNewEventList count];
}
- (NewEvent *)objectInListAtIndex:(NSUInteger)theIndex
{
return [self.masterNewEventList objectAtIndex:theIndex];
}
- (void)addNewEventWithEvent:(NewEvent *)event
{
[self.masterNewEventList addObject:event];
}
@end
Thanks in advance for taking a look.