1.Adding Edit button on the left of the NavigationBar
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.leftBarButtonItem=self.editButtonItem; //adding editButtonItem.
self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
}
2. Delete record from CoreData
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle==UITableViewCellEditingStyleDelete) {
NSString *name=((People *)[self.peopleArray objectAtIndex:indexPath.row]).name;
[self.context deleteObject: [self.peopleArray objectAtIndex:indexPath.row]];
[self viewDidAppear:YES];
NSError *error;
if ([self.context save:&error]) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Deleted" message:[NSString stringWithFormat:@"Name:%@ has deleted",name] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}