Veuillez noter où se trouve le NSLOG. Tout ce qu'il affiche dans le journal est les trois premiers éléments du nomSection. Après quelques tests, j'ai découvert qu'il affiche combien de clés il y a parce que si j'ajoute une clé à la plist, il enregistrera un quatrième élément dans log. NomSection doit être un tableau des chaînes qui composent le tableau de clés dans le fichier plist.iphone Problème lors de l'utilisation d'une cellule personnalisée
Le fichier plist possède 3 dictionnaires, chacun avec plusieurs tableaux de chaînes. Le code choisit le dictionnaire avec lequel je travaille correctement, puis utilise les noms des tableaux comme des sections dans la table et les chaînes dans chaque tableau comme quoi afficher dans chaque cellule.
donc si le dictionnaire je travaille avec dispose de 3 tableaux, NSLog affiche 3 chaînes à partir du premier tableau:
2010-05-01 17: 03: 26.957 listes de vérification [63926: 207] string0 2010- 05-01 17: 03: 26.960 Listes de contrôle [63926: 207] string1 2010-05-01 17: 03: 26.962 Listes de contrôle [63926: 207] string2
puis arrêtez avec: 2010-05-01 17:03: 26.963 Listes de contrôle [63926: 207] * Fin de l'application due à l'exception non interceptée 'NSRangeException', raison: '* - [NSCFArray objectAtIndex:]: index (3) au-delà des limites (3)'
si j'ajouté un tableau dans le dictionnaire, il log 4 éléments au lieu de 3.
J'espère que cette explication est logique ...
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [keys count];
}
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger) section {
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
return [nameSection count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger section = [indexPath section];
NSString *key = [keys objectAtIndex: section];
NSArray *nameSection = [names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
static NSString *ChecklistCellIdentifier = @"ChecklistCellIdentifier ";
ChecklistCell *cell = (ChecklistCell *)[tableView
dequeueReusableCellWithIdentifier: SectionsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChecklistCell"
owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[ChecklistCell class]])
cell = (ChecklistCell *)oneObject;
}
NSUInteger row = [indexPath row];
NSDictionary *rowData = [self.keys objectAtIndex:row];
NSString *tempString = [[NSString alloc]initWithFormat:@"%@",[nameSection objectAtIndex:row]];
NSLog(@"%@",tempString);
cell.colorLabel.text = [tempArray objectAtIndex:0];
cell.nameLabel.text = [tempArray objectAtIndex:1];
return cell;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
-(NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section{
NSString *key = [keys objectAtIndex:section];
return key;
}
Pourriez-vous s'il vous plaît réduire le code juste à la partie pertinente? – Cesar
Je l'ai fait. Je ne sais pas où dans les délégués il pourrait être foiré – Brodie