J'essaie de supprimer une ligne dans la vue de table après confirmation de l'utilisateur, en utilisant une vue d'alerte. Cependant, je ne sais pas comment laisser la méthode UIAlertViewDelegate
savoir quelle ligne de la table à supprimer.Transmettre les informations au délégué UIAlertView
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert_delete = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"Confirm Delete %@",[names objectAtIndex:indexPath.row] ] message:@"Warning all student data will be earsed" delegate:self cancelButtonTitle:@"Dismess" otherButtonTitles:@"YES", nil];
[alert_delete show];
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
en méthode d'alerte i essayer gérer à supprimer la ligne de la table et base de données
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString*title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"YES"]) {
// how to pass indexPath.row to alertview
[names removeObjectAtIndex:indexPath.row];
}
}
Qu'est-ce que la trace de la pile d'erreurs? Vous venez de poster du code et vous ne dites pas ce qui ne fonctionne pas – Foriger
Et quel est le problème réel? BTW, en comparant les valeurs textuelles des boutons entravera vos tentatives de i18n. – trojanfoe
je dois passer indexPath.row à délégué uialert –