- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
DefaultContactSelectViewController *view = [[self storyboard] instantiateViewControllerWithIdentifier:@"DefaultContactView"];
view.recordID = recordID;
view.phones = phones;
view.emails = emails;
view.first_name = first_name;
view.last_name = last_name;
view.delegate = self;
[peoplePicker pushViewController:view animated:YES];
return NO;
}
在上面的代码示例中,我在选择联系人后推送自定义联系人 View Controller 。问题是如果联系人是从搜索结果中选择的,然后用户单击返回返回联系人选择器,搜索结果将被清除。
如果上面的代码返回 YES,这个问题就不会发生,但是它会推送默认的联系人 View ,这不是我想要的。
如果您知道如何解决此问题,请提前致谢。
最佳答案
您可能应该编写自定义的 PeoplePickerViewController,因为您永远无法充分控制 Apple 的默认 Controller 。
无论如何,对于您当前的问题,这是您需要做的:
声明三个新属性(根据您是否使用 ARC 使用适当的声明 - 我假设没有 ARC)
@property (nonatomic, assign) ABPeoplePickerNavigationController *peoplePicker;
@property (nonatomic, assign) UIViewController *peoplePickerRootViewController;
@property (nonatomic, copy) NSString *currentSearchString;
现在,当您显示人员选择器时,添加以下行:
// save people picker when displaying
self.peoplePicker = [[[ABPeoplePickerNavigationController alloc] init] autorelease];
// save it's top view controller
self.peoplePickerRootViewController = self.peoplePicker.topViewController;
// need to see when view controller is shown/hidden - viewWillAppear:/viewWillDisappear: won't work so don't bother with it.
self.peoplePicker.delegate = self;
现在,我们将在推送人员 View 之前保存搜索字符串:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
self.currentSearchString = nil;
if ([self.peoplePickerRootViewController.searchDisplayController isActive])
{
self.currentSearchString = self.peoplePickerRootViewController.searchDisplayController.searchBar.text;
}
// other stuff...
显然,在这个类中实现 UINavigationControllerDelegate。当 Root View 重新进入 View 时,我们将强制显示搜索结果 View 。这是 navigationController:willShowViewController:animated:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (navigationController == self.peoplePicker)
{
if (viewController == self.peoplePickerRootViewController)
{
if (self.currentSearchString)
{
[self.peoplePickerRootViewController.searchDisplayController setActive: YES];
self.peoplePickerRootViewController.searchDisplayController.searchBar.text = self.currentSearchString;
[self.peoplePickerRootViewController.searchDisplayController.searchBar becomeFirstResponder];
}
self.currentSearchString = nil;
}
}
}
如果不使用 ARC,不要忘记在 dealloc 中释放 currentSearchString。
小警告:当 ABPeoplePickerNavigationController 试图隐藏搜索结果 View 时,当您选择一个人时会出现轻微的闪烁。
关于ios - ABPeoplePickerNavigationController shouldContinueAfterSelectingPerson 返回搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15939229/
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker s
我正在尝试获取选定的手机号码 ABMultiValueRef phones = ABRecordCopyValue(person, property); CFStringRef phoneNumber
我正在运行以下代码,它利用 Apple 的地址簿 UI。取消方法有效,但我的 shouldContinueAfterSelecting 无效。当我单击通讯簿 View Controller 中的联系人
我是一名优秀的程序员,十分优秀!