我从视图控制器启动CNContactPickerViewController,但是如何更改其中的搜索栏的文本颜色.导航栏为深蓝色,在iOS11中,默认searchbartext为黑色.
我是iOS开发的新手,想知道我是否可以修改CNContactPickerViewController tableViewCell已经使用我的应用程序的联系人以不同的方式显示.
并向未使用我的应用的联系人添加邀请按钮.
是否使用CNContactPickerViewController了正确的方法?
谢谢!
我开始知道CNContactPickerViewController中的搜索栏不允许选择搜索到的联系人.我还看了关于这个问题的其他堆栈溢出问题.这似乎是iOS的bug.但我想知道,有没有办法隐藏或禁用CNContactPickerViewController的搜索栏?因为如果这不起作用,那么我不想展示它.
您好,我正在尝试构建一个界面,列出所有联系人,就像Contacts具有Phone相同UI. 到目前为止我所尝试的如下。基本上我尝试CNContactPickerViewController使用ContactsUI. UIViewControllerRepresentable然而我得到的是一张空白的白页。
struct ContactsViewController: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<ContactsViewController>) -> CNContactPickerViewController {
let controller = CNContactPickerViewController()
controller.delegate = context.coordinator
controller.displayedPropertyKeys = [CNContactGivenNameKey]
return controller
}
func updateUIViewController(_ uiViewController: CNContactPickerViewController, context: UIViewControllerRepresentableContext<ContactsViewController>) {
print("updating")
}
func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
class Coordinator: NSObject, CNContactPickerDelegate {
var parent: ContactsViewController
init(_ contactsViewController: ContactsViewController) {
self.parent = contactsViewController
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及 SwiftUI 文件;
struct ContactsView: View {
var …Run Code Online (Sandbox Code Playgroud) 我知道如何在iOS中选择联系人(使用CNContactPickerViewController),但我如何为联系人选择特定的电话号码,而不是整个联系人本身?根据文档,这应该是可能的,但我没有发现如何.
编辑:这是我的代码
CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
contactPicker.delegate = self;
contactPicker.displayedPropertyKeys = @[CNContactGivenNameKey, CNContactImageDataAvailableKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactThumbnailImageDataKey, CNContactIdentifierKey];
[self presentViewController:contactPicker animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
所以,我确实设置了displayProperties,但结果是一样的,即使我只选择了CNContactPhoneNumbersKey,我也没有提供所有联系人的号码,以便我可以选择一个特定的号码.
我错过了什么?
编辑2:请求的回调方法.我不知道它们有多重要,但不过.
-(void) contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact{
//NSLog(@"Contact : %@",contact);
NSString* contactName = [NSString stringWithFormat:@"%@%@%@", contact.givenName, @" ", contact.familyName];
[currentButton setTitle:contactName forState:UIControlStateNormal];
[currentName setText:contactName];
...
}
-(void) contactPickerDidCancel:(CNContactPickerViewController *)picker {
//NSLog(@"Cancelled");
}
Run Code Online (Sandbox Code Playgroud)