gpt4 book ai didi

ios - 无法编辑或关闭 CNContactViewController (iOS)

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:56:10 28 4
gpt4 key购买 nike

我在我的应用程序中展示了一个 CNContactViewController 的实例。我希望用户既能编辑联系人,又能关闭这个 View Controller 。下面是呈现 View Controller 的代码,它嵌入在 UINavigationController 中。正如您在代码中看到的,我有 allowsEditing = YES,但查看屏幕截图;你可以看到我无法编辑。任何人都可以帮我看看我错过了什么?谢谢!

CNContactViewController *contactController = [CNContactViewController viewControllerForUnknownContact:contact];

contactController.allowsEditing = YES;
contactController.delegate = self;

contactController.contactStore = store;

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];

编辑:我尝试了@WrightCS 建议的另一种方法:

[self presentViewController:contactController animated:YES completion:nil];

并且,确保添加这个委托(delegate)方法:

- (void)contactViewController:(CNContactViewController *)viewController
didCompleteWithContact:(CNContact *)contact{
[self dismissViewControllerAnimated:YES completion:nil];

}

但是,反复得到这个错误日志:

[CNUI ERROR] Contact view delayed appearance timed out

enter image description here

最佳答案

与其创建 UINavigationController 实例,不如尝试直接呈现接触 Controller 。

[self presentViewController:contactController animated:YES completion:nil];

CNContactViewControllerDelegate

- (void)contactViewController:(CNContactViewController *)viewController 
didCompleteWithContact:(CNContact *)contact;

出现在主线程上

dispatch_async(dispatch_get_main_queue(), ^{
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
});

关于ios - 无法编辑或关闭 CNContactViewController (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40566195/

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