gpt4 book ai didi

ios - 在 ABPeoplePickerNavigationController 中添加滑动删除功能

转载 作者:行者123 更新时间:2023-11-29 03:43:21 35 4
gpt4 key购买 nike

我正在使用苹果的地址簿制作一个简单的联系人应用程序,并且根据他们的开发人员网站中提供的信息,我已经成功创建了联系人应用程序。但我的删除功能有问题。我已经添加了删除代码

[picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];

并且出现删除按钮,但是当我单击删除时它没有响应,但当我下次重新加载时该联系人确实被删除。我已经搜索过,但找不到合适的解决方案,似乎每个人都有同样的问题。

现在我计划在 PeoplePickerNavigationController 上添加滑动删除功能。我找到了有关如何在 PeoplePickerNavigationController 上标记联系人的代码,并且它有效。现在我正在尝试调整代码以添加滑动删除功能,但我在实现它时遇到了麻烦。你能帮我修改滑动删除的代码吗?这是当我单击联系人时会打上复选标记的代码。我需要替换此事件以滑动删除。

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

这是我创建的函数,当我单击删除按钮时应该调用该函数,但您可以添加自己的删除函数,只要它有效即可。

-(void)deleteContct
{
ABAddressBookRef addressBook= ABAddressBookCreate();
ABAddressBookRemoveRecord(addressBook, (ABRecordRef)person,NULL);
ABAddressBookSave(addressBook, NULL);

}

最佳答案

我无法在删除时添加滑动操作,但暂时我设法在警报 View 中添加单击删除。如果您可以在此代码中实现删除时滑动的代码,请发布您的答案,我会将其标记为最佳答案,但目前这是我得到的最佳答案。

-(BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {

person12=person;

if(deleteFlag)
{
UIView *view = peoplePicker.topViewController.view;
UITableView *tableView = nil;
for(UIView *uv in view.subviews)
{
if([uv isKindOfClass:[UITableView class]])
{
tableView = (UITableView*)uv;
break;
}
}

//[tableView setEditing:YES]; // I was trying to write code for this delete function, for swipe delete
if(tableView != nil)
{



[self tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:[tableView indexPathForSelectedRow]];

}
return NO;
}
else
{
[peoplePicker dismissModalViewControllerAnimated:NO];

ABPersonViewController *picker = [[ABPersonViewController alloc] init];
picker.personViewDelegate = self;
picker.displayedPerson = person;

// Allow users to edit the person’s information
picker.allowsEditing = YES;


[self.navigationController pushViewController:picker animated:YES];

return YES;
}
}

//Deletes contact here

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
//NSLog(@"%@",[alertView buttonTitleAtIndex:buttonIndex]);
if([alertView buttonTitleAtIndex:buttonIndex]==@"Delete") // This is where my click on delete works
{
ABAddressBookRef addressBook= ABAddressBookCreate();
ABAddressBookRemoveRecord(addressBook, (ABRecordRef)person12,NULL);
ABAddressBookSave(addressBook, NULL);
CFRelease(addressBook);

}
else if([alertView buttonTitleAtIndex:buttonIndex]==@"Delete All") // This is for a different menu option for deleting all contact at once
{
ABAddressBookRef addressBook= ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(people); i++)
{
self.person12 = CFArrayGetValueAtIndex(people, i);
ABAddressBookRemoveRecord(addressBook, self.person12,NULL);
}
CFBridgingRelease(people);
ABAddressBookSave(addressBook,NULL);
[self showContacts];
CFRelease(addressBook);
}

}

//用于显示删除的警报 View 选项

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *str=[[NSString stringWithFormat:@"%@", (__bridge_transfer NSString *)ABRecordCopyValue(self.person12, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

NSString *delMsg = [NSString stringWithFormat:@"Delete Contact %@",str];

if(editingStyle==UITableViewCellEditingStyleDelete)
{
UIAlertView *message= [[UIAlertView alloc] initWithTitle:delMsg message:@"This action can't be undone, are you sure?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];


[message show];



}
}

关于ios - 在 ABPeoplePickerNavigationController 中添加滑动删除功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051282/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com