At the suggestion of another member, I've rewritten part of my recent project. I've now fixed the trouble I was having earlier, only to spend a few hours struggling with this one. Any/all help is much appreciated.
When I try to add more than one item to my NSTableView with a NSMutableArray, it replaces all of the entries in dateList with the most recent entry. Here's my .m file. The NSLog I have setup in "setting d object date to %@", will get called the nth time as I continue to add dates.
@implementation TableViewController
@synthesize myDatePicker;
NSString *myRenamed = @"CHANGED";
int test = 0;
- (id) init{
self = [super init];
if (self) {
dateList = [[NSMutableArray alloc] init];
}
return self;
}
-(void) awakeFromNib{
[myDatePicker setDateValue: [NSDate date]];
[self.myDatePicker sendActionOn:NSLeftMouseDown];
NSLog(@"Hello from TableView at time: %@", myDatePicker.dateValue);
}
- (IBAction)datePickerAction:(id)sender{
test = 0;
[self getSetDate];
NSLog(@"getSetDate Finished with date %@", myRenamed);
[self myTableAdd];
NSLog(@"datePickerAction Finished");
}
- (void)getSetDate{
NSLog(@"Entering getSetDate%@", (myDatePicker.dateValue));
//set date to local & set format set on xib start
NSDate *myNewDate = [myDatePicker dateValue];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYYMMdd"];
myRenamed = [dateFormat stringFromDate:myNewDate];
NSLog(@"Ending getSetDate with %@",myRenamed);
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView{
return [dateList count];
}
-(id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
Date *d = [dateList objectAtIndex:row];
NSString *identifier = [tableColumn identifier];
d.date=myRenamed;
[d setDate:d.date];
NSLog(@"setting d object date to %@", d.date);
test ++;
return [d valueForKey:identifier];
}
- (void) myTableAdd{
NSLog(@"Called myTableAdd");
[dateList addObject:[[Date alloc] init]];
[tableview reloadData];
}
Image: http://cl.ly/NaEu This is what happens, all the previous date entries are changed to the last-clicked entry. All help is appreciated.