2010-04-28 5 views
-1

-je ajouter ces méthodes dans le fichier .h:supprimer dans tableView

- (IBAction)EditTable:(id)sender; 

- (IBAction) DeleteButtonAction: (id) expéditeur;

et dans le fichier .m:

  • (IBAction) DeleteButtonAction: (id) sender { [tableList removeLastObject]; [Table reloadData]; }

  • (IBAction) partie modifiables: (id) sender {

    si (self.editing)

    {

    [super setEditing:NO animated:NO]; 
    [Table setEditing:NO animated:NO]; 
    [Table reloadData]; 
    [self.navigationItem.leftBarButtonItem setTitle:@"Edit"]; 
    [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain]; 
    

    }

    autre {

    [super setEditing:YES animated:YES]; 
    [Table setEditing:YES animated:YES]; 
    [Table reloadData]; 
    [self.navigationItem.leftBarButtonItem setTitle:@"Done"]; 
    [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone]; 
    

    }

}

quand je lance le programme et cliquez sur le bouton Supprimer (touche rouge) le programme est d'arrêter! quel est le problème? s'il vous plaît toute aide?


vous êtes mal :(

OK, encore une fois mon code dans le fichier .h est:

- (IBAction)EditTable:(id)sender; 
- (IBAction)DeleteButtonAction:(id)sender; 

et dans le fichier .m est:

- (IBAction)DeleteButtonAction:(id)sender{ 
    [tableList removeLastObject]; 
    [Table reloadData]; 
} 
- (IBAction) EditTable:(id)sender{ 

    if(self.editing) 

{ 
[super setEditing:NO animated:NO]; 
[Table setEditing:NO animated:NO]; 
[Table reloadData]; 
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"]; 
     [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain]; 
} 
else 
{ 
[super setEditing:YES animated:YES]; 
[Table setEditing:YES animated:YES]; 
[Table reloadData]; 
[self.navigationItem.leftBarButtonItem setTitle:@"Done"]; 
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone]; 
} } 

quand je exécuter le programme et cliquez sur le bouton de suppression (bouton rouge) le programme est en panne! Quel est le problème? s'il vous plaît toute aide?

+0

-1 pour le formatage paresseux et la non-adhérence du style d'objet commun. Si vous voulez de l'aide, au moins, il est facile de lire votre code! –

Répondre

1

Si je ne me trompe pas, vous voulez supprimer la cellule du tableView lorsque le bouton de suppression est cliqué ....

Vous devez appeler une autre méthode de tableview:

//To Delete the Data 
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 
    // Updates the appearance of the Edit|Done button as necessary. 
    [super setEditing:editing animated:animated]; 
    [tblViewBM setEditing:editing animated:YES]; 
    // Disable the add button while editing. 
} 


- (void)tableView:(UITableView *)tableView commitEditingStyle: 
(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

if (editingStyle == UITableViewCellEditingStyleDelete) { 

//Use your Array from which you need to delete the data. 
    NSMutableDictionary *dict=(NSMutableDictionary *)[appDel.BookMarkAry objectAtIndex:indexPath.row]; 
    type=[dict valueForKey:@"type"]; 

    [appDel.BookMarkAry removeObjectAtIndex:indexPath.row]; 


    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 


    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
} 

Je suis Bien sûr, cela vous aidera certainement à supprimer la cellule avec des données du tableau également.