繁体   English   中英

CNContactViewController对响应者链做了一些奇怪的事情

[英]CNContactViewController does something strange with responder chain

我正在尝试在我的应用程序中实现UIKeyCommand快捷方式,并且在大多数情况下,它似乎可以正常工作。 除了当我在一个模式来看,它似乎做一些奇怪的事情出现CNContactViewController:在CNContactViewController被驳回后,键盘快捷键仍然显示在可发现HUD但停止整个应用程序的工作,即使呈现视图控制器手动调用becomeFirstResponder后CNContactViewController被关闭了。

这是来自FirstViewController:

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

我用的是私有API看到firstResponder ,并且它被正确显示FirstViewController作为第一个响应者。 可以肯定调用canBecomeFirstResponder也可以调用keyCommands方法。 按住Command键将打开可发现性HUD,并显示键盘快捷键。

显然,这是Contacts框架的某种错误。 只是不确定如何解决此问题。 在1秒内在dispatch_asyncdispatch_after调用[self becomeFirstResponder]无效。 很想听听一些想法。

谢谢。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM