Je veux utiliser l'option "Swipe pour supprimer" l'option dans mon projet.
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSDictionary *userData = [_contactsArray objectAtIndex:indexPath.row];
NSLog(@"delete row %@",userData);
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
4 Réponses :
Essayez ceci:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
On dirait que vous tournez le drapeau tableview.editing code> sur afin que les lignes apparaissent avec le signe moins. Essayez Gox> Self.tableview.editing = Oui; Code> et faites-le NO CODE> ou commencez simplement que la ligne de sortie. P>
Vous remplacez les méthodes de délégué correctes pour «Swipe pour supprimer» la fonctionnalité. En ce qui concerne les signes moins:
Masquer le signe moins Signe Comme ceci: P>
self.yourTableView.editing = YES;
Créez d'abord votre vue sur la table et définissez la méthode du délégué et de votre source de données à cela.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
développeur.apple.com/library/ios/documentation/uikit/referenc e / ...
Stackoverflow.com/Questtions/3020922/...
Vous remplacez les méthodes uablesViewelegate correctes. Mais définissez-vous la propriété "Modification" de votre UitaireView vers
Oui CODE> N'importe Où dans votre code? Si tel est le cas, cela entraînera la visibilité des signes rouges moins les signes.@ hw731 merci pour votre réponse. Ça marche pour moi, j'ai fait une petite erreur