I am doing a simple contacts app using Apple's addressbook and as provided in their developer site I have managed to create the contact app. But I have problem in the delete function. I have added the code for deletion
[picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];
and the delete button appears, but when I click on delete it doesnt respond but the contact does get deleted when I reload next time. I have searched through but couldnt find a proper solution for this, seems like everyone has same issue.
Now I am planning to add a swipe on delete function on the PeoplePickerNavigationController. I have found a code on how to mark the contact on PeoplePickerNavigationController and it works. Now I am trying to tweak the code to add the swipe on delete function but I am having trouble implementing it. Can you help me modify the code for swipe on delete? This is the code that puts a check mark when I click on a contact. I need to replace this event to swipe on delete.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
UIView *view = peoplePicker.topViewController.view;
UITableView *tableView = nil;
for(UIView *uv in view.subviews)
{
if([uv isKindOfClass:[UITableView class]])
{
tableView = (UITableView*)uv;
break;
}
}
if(tableView != nil)
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[tableView indexPathForSelectedRow]];
if(cell.accessoryType == UITableViewCellAccessoryNone){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
[cell setSelected:NO animated:YES];
}
return NO;
}
This is the function I created that should be called when I click on delete button, but you can add your own delete function as long as it works.
-(void)deleteContct
{
ABAddressBookRef addressBook= ABAddressBookCreate();
ABAddressBookRemoveRecord(addressBook, (ABRecordRef)person,NULL);
ABAddressBookSave(addressBook, NULL);
}