tags:

views:

95

answers:

2

I just add this methods in .h file :

- (IBAction)EditTable:(id)sender;

- (IBAction)DeleteButtonAction:(id)sender;

and in .m file :

  • (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];
    

    }

}

when I run the program and click the delete button (red button) the program is stop ! whats the problem ? please any help ?

A: 

you are evil :(

OK, again my code in .h file is :

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

and in .m file is :

- (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];
} }  

when I run the program and click the delete button (red button) the program is crash ! whats the problem ? please any help ?

Rona
A: 

If I am not wrong then you want to delete the cell of the tableView when delete button is clicked....

You need to call one other method of 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]; } }

I am sure this will Definately help you to delete the cell with data from array also.

Ajay Sharma