everytime I call the method -(void)setArrayCheckOut:(int)num in another class the array arrayCheckout is empty. Calling -(IBAction)reloadTable:(id)sender after -(void)setArrayCheckOut:(int)num "results in reload table - (null), 0".
Any idea what goes wrong?
so long
@implementation CheckOut
-(id)init
{
[super init];
tableCheckOut = [[NSTableView alloc]init];
if (!arrayCheckOut)
{
arrayCheckOut = [[NSMutableArray alloc]init];
[arrayCheckOut addObject:@"-"];
}
return self;
}
-(void)setArrayCheckOut:(int)num
{
switch (num) {
case 170:
[arrayCheckOut addObject:@"T20, T20, DB"];
break;
default:
[arrayCheckOut addObject:@"-"];
break;
}
NSLog(@"array = %@",[arrayCheckOut objectAtIndex:0]);
[tableCheckOut reloadData];
}
-(IBAction)reloadTable:(id)sender
{
NSLog(@"reload table - %@, %d",[arrayCheckOut objectAtIndex:0],[arrayCheckOut count]);
[tableCheckOut reloadData];
}
- (int)numberOfRowsInTableView:(NSTableView *)tv
{
return [arrayCheckOut count];
}
- (id)tableView:(NSTableView *)tv
objectValueForTableColumn:(NSTableColumn *)tColumn
row:(int)row
{
NSString *v = [arrayCheckOut objectAtIndex:row];
return v;
}
@end
setArrayCheckOut:include a magic number (170), magic and un-localized string literals, use ofintwhereNSIntegerorNSUIntegermight be more appropriate (also a problem in your data source methods), and the non-descriptive name of the method. I suggest defining constants for the number and strings, localizing the strings usingNSLocalizedString(since they seem to be intended for display to the user), switching toNSIntegerorNSUInteger, and renamingsetArrayCheckOut:to something that more clearly states the method's goal, rather than just its implementation.