I’ve made a project which is a kind of Todo List but it doesn’t work. My tableView has a blue halo on it but nothing appear.
Here is the code of TPRendu.h:
@interface TPRendu : NSObject
{
IBOutlet NSButton *boutonAjouter;
IBOutlet NSTableView *tableauEtudiant;
NSMutableArray *sourceTable;
}
-(IBAction)ajouterEtudiant:(id)sender;
@end
And the code of TPRendu.m:
#import "TPRendu.h"
@implementation TPRendu
-(id)init
{
[super init];
NSLog(@"init");
//init du tableau
sourceTable = [[NSMutableArray alloc] init];
return self;
}
-(IBAction)ajouterEtudiant:(id)sender
{
[sourceTable addObject:@"test"];
[tableauEtudiant reloadData];
NSLog(@"Nombre éléments ajoutés: %d",[sourceTable count]);
}
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tv
{
return [sourceTable count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tc row:(NSInteger)rowIndex
{
return [sourceTable objectAtIndex:rowIndex];
}
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tc row:(NSInteger)rowIndex
{
[sourceTable replaceObjectAtIndex:rowIndex withObject:anObject];
}
@end
As you can see, it’s very simple. I haven’t made any binding in IB except the Referencing outlet for tableauEtudiant and for the NSButton.
The thing is: I’ve made a similar program a month ago that work flawlessly, I’ve made this on the same template and it doesn’t work. It seems that the NSMutableArray isn’t linked with the NSTableView (the NSLog in ajouterEtudiant works well for example).
Any thought?
Thanks.
First guess: you didn’t connect the table’s dataSource outlet to an instance of the controller that contains the code you posted.