Bonjour à tous,
J'aurais besoin d'une petite aide pour remplir un NSTableView.
Donc je bosse actuellement sur un petit projet dans lequel j'ai besoin d'afficher une liste d'étudiants (comprenant un id, une promo, un first name, et un last name) récupérée à partir d'un fichier CSV.
J'ai créé le parseur jusque là tout fonctionne bien. Par contre lorsqu'il s'agit d'afficher le résultat dans une NSTableView, je bloque
Bon passons direct au code pour pas perdre de temps.
Mon interface du controller est la suivante :
Et son implémentation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 #import <Foundation/Foundation.h> #import "ParseCsv.h" @interface CheckStatsViewController : NSObject { IBOutlet NSTableView *checkStatsTable; NSMutableArray *studentsList; } - (NSUInteger)numberOfRowsInTableView:(NSTableView *)checkStatsTable; - (id)tableView:(NSTableView *)checkStatsTable objectValueForTableColumn:(NSTableColumn *)checkStatsTableColumn row:(NSInteger)i; @end
La liaison data-source dans le .xib a aussi été mise en place.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #import "CheckStatsViewController.h" @implementation CheckStatsViewController - (id)init { self = [super init]; if (self) { studentsList = [[NSMutableArray alloc] init]; NSString *idstudent=@"ID Student",*grade=@"Grade",*lastName=@"Last Name",*firstName=@"First Name"; NSArray *csvKeys = [[NSArray alloc] initWithObjects:grade,idstudent,lastName,firstName,nil]; ParseCsv *studentListCsv = [[ParseCsv alloc] initWithPath:@"/Users/****/Desktop/StudentList.csv"]; //Chemin temporaire [studentListCsv parseCsv]; NSInteger i=0; for (i=0; i<[studentListCsv.parsedCsv count]; i++){ NSMutableDictionary *student = [[NSMutableDictionary alloc] initWithObjects:[studentListCsv.parsedCsv objectAtIndex:i] forKeys:csvKeys]; [studentsList addObject:student]; } } return self; } - (NSUInteger)numberOfRowsInTableView:(NSTableView *)checkStatsTable { return [studentsList count]; } - (id)tableView:(NSTableView *)checkStatsTable objectValueForTableColumn:(NSTableColumn *)checkStatsTableColumn row:(NSInteger)i { id theRecord, theValue; NSParameterAssert(i >= 0 && i < [studentsList count]); theRecord = [studentsList objectAtIndex:i]; theValue = [theRecord objectForKey:[checkStatsTableColumn identifier]]; return theValue; } - (void)dealloc { [super dealloc]; studentsList = nil; [studentsList release]; } @end
Lorsque je fais un NSLog(@"%@",studentsList); juste après la boucle for de mon init, j'obtient un tableau de la forme :
(
{
"First Name" = FName_student1;
Grade = Grade_student1;
"ID Student" = id_student1;
"Last Name" = LName_student1;
},
{
"First Name" = FName_student2;
Grade = Grade_student2;
"ID Student" = id_student2;
"Last Name" = LName_student2;
}
)
Identique à la doc Apple, mais impossible d'afficher les résultats ben rangés par lignes et pas colonnes ...
Je vous remercie d'avance pour votre aide
Partager