CNContactViewController对响应者链

时间:2015-11-15 17:42:56

标签: ios first-responder uiresponder cncontactviewcontroller

我正在尝试在我的应用程序中实现UIKeyCommand快捷方式,并且在大多数情况下,它似乎工作正常。除非我在模态视图中呈现CNContactViewController,它似乎做了一些奇怪的事情:CNContactViewController被解除后,键盘快捷键仍显示在可发现性HUD中但在整个应用程序中停止工作,即使呈现视图控制器手动调用{{ 1)} CNContactViewController被解雇后。

这是来自FirstViewController:

becomeFirstResponder

我使用私有API查看- (void) showCNContacts { CNContact * contact = [[CNContact alloc] init]; CNContactViewController *createContact = [CNContactViewController viewControllerForNewContact: contact]; createContact.delegate = self; createContact.allowsActions = NO; CNContactStore *store = [[CNContactStore alloc] init]; createContact.contactStore = store; UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:createContact]; navigation.modalPresentationStyle = UIModalPresentationPageSheet; [self presentViewController: navigation animated:YES completion: ^{ NSLog(@"presented CNContactVC - responder = %@", [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]); }]; } - (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact { [viewController dismissViewControllerAnimated:YES completion:^{ [self becomeFirstResponder]; NSLog(@"after dismissing CNContactVC - responder = %@", [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(firstResponder)]); }]; } ,并正确显示firstResponder作为第一个响应者。肯定会调用FirstViewControllercanBecomeFirstResponder方法也是如此。按住Command键会显示可发现性HUD,并显示键盘快捷键。

这显然是Contacts框架的某种错误。只是不知道如何解决这个问题。在keyCommands[self becomeFirstResponder]内拨打dispatch_async 1秒钟无效。很想听听一些想法。

感谢。

1 个答案:

答案 0 :(得分:2)

我想到的解决方法是将CNContactViewController推送到导航堆栈,而不是尝试以模态方式呈现它。