jeoData is a singleton...the table displays just fine, NSLog verifies the correct row is selected, however, jeoData.crewList.count returns zero after adding the object to the NSMutableArray...
in the jeoData singleton, employeeList is initialized identically to crewList.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Employee *employee = [jeoData.employeeList objectAtIndex:indexPath.row];
[jeoData.crewList addObject:employee];
NSLog(@"SelectCrewVC: added: %@ %@", employee.firstName, employee.lastName);
NSLog(@" total selected: %lu", (unsigned long)jeoData.crewList.count);
}
NSLog:
2014-10-17 15:09:41.590 SaveAndLoad[98371:414247] SelectCrewVC: added: Jacob Johnson
2014-10-17 15:09:41.591 SaveAndLoad[98371:414247] total selected: 0
...even the didDeselectRow selects the correct object to display, but I cannot figure out why I can't get the object into the crewList array.
Any help would be greatly appreciated, because I'm stumped.
EDIT: adding code as per request
JEOData.m (singleton... where init occurs)
@implementation JEOData
@synthesize employeeList;
@synthesize leaseList;
@synthesize crewList;
@synthesize workReport;
+(id)sharedManager {
static JEOData *sharedJEOData = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^ {
sharedJEOData = [[self alloc] init];
});
return sharedJEOData;
}
-(id)init {
if (self = [super init]) {
employeeList = [[NSMutableArray alloc] init];
leaseList = [[NSMutableArray alloc] init];
crewList = [[NSMutableArray alloc] init];
workReport = [[NSMutableArray alloc] init];
}
return self;
}
@end
jeoData is declared in the @interface of the header file of the View Controller
@interface SelectCrewViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
JEOData *jeoData;
NSMutableArray *crewList; <---created only in troubleshooting, unused now
}
ViewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
jeoData = [JEOData sharedManager];
self.crewSelectTable.allowsMultipleSelection = YES;
NSLog(@"Num of employees total :%lu", (unsigned long)jeoData.employeeList.count);
NSLog(@" employees in crew list: %lu", (unsigned long)jeoData.crewList.count);
}
NSLog returns:
2014-10-17 15:09:39.473 SaveAndLoad[98371:414247] Num of employees total :3
2014-10-17 15:09:39.474 SaveAndLoad[98371:414247] employees in crew list: 0
So, you can see that jeoData.employeeList contains the right objects, as does jeoData.leaseList. I know that DidSelectRows is being called because of the NSLog, so I know that the Employee object is well and alive, yet it will not let me add the little bugger to the crewList mutable array.
I am fairly certain that I am just overlooking something, yet I am at a loss to see what it is.
Please, help us, Obi-wan Kenobi, you're our only hope.