J'ai effectué des recherches sur tout le Web et mon code semble être presque identique à tout ce qui existe, mais je ne parviens pas à modifier mon UITableView pour insérer une ligne. Lorsque je clique sur le bouton d'édition, toutes mes lignes existantes obtiennent le contrôle de suppression, mais je n'obtiens aucune ligne supplémentaire pour l'insertion. Je tire mes cheveux pour ce qui semble être une chose simple. Qu'est-ce que je rate?Impossible d'obtenir le contrôle d'insertion dans UITableView
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[categoryTV setEditing: editing animated:animated];
NSIndexPath *ip = [NSIndexPath indexPathForRow:[[appDelegate appCategories] count] inSection:0];
[self.categoryTV beginUpdates];
if (editing) {
[categoryTV insertRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationLeft];
} else {
[categoryTV deleteRowsAtIndexPaths:[NSArray arrayWithObject:ip] withRowAnimation:UITableViewRowAnimationFade];
}
[self.categoryTV endUpdates];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
if (indexPath.row >= [[appDelegate appCategories] count])
cell.textLabel.text = NSLocalizedString(@"New Category", @"NewCategoryCellText");
else
cell.textLabel.text = [[[appDelegate appCategories] objectAtIndex:indexPath.row] detailValue];
....
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (self.editing) {
return [[appDelegate appCategories] count] + 1;
} else {
return [[appDelegate appCategories] count];
}
}
Comme indiqué, j'ai oublié d'inclure ma version de la méthode suggérée, maintenant montrée ci-dessous. Merci.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [[appDelegate appCategories] count]) {
return UITableViewCellEditingStyleInsert;
} else {
return UITableViewCellEditingStyleDelete;
}
}
Merci. J'ai mis en place une version de la méthode que vous avez suggérée et édité ma question pour inclure ma version. – Shawn
Êtes-vous toujours en train de voir seulement le contrôle de suppression? – rickharrison
Malheureusement, oui. – Shawn