用户在搜索栏中快速搜索联系人时如何使用复选框

时间:2018-09-20 07:22:22

标签: swift cncontactpicker

我想通过搜索栏搜索联系人,并通过使用联系人选择器快速选中一个复选框。所以我尝试了一下,我搜索了联系人,并且只显示名称,没有用于选择联系人的复选框。这是我的代码:

       let cnPicker = CNContactPickerViewController()
            cnPicker.delegate = self
            self.present(cnPicker, animated: true, completion: nil)
            do {
                try contactStore.enumerateContacts(with: CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactMiddleNameKey as CNKeyDescriptor, CNContactEmailAddressesKey as CNKeyDescriptor,CNContactPhoneNumbersKey as CNKeyDescriptor])) {
                    (contact, cursor) -> Void in
                    self.res = contact
                    ///let data = Data(name: contact.givenName)
                    //self.dataArray?.addObject(data)
                }
            }
            catch
            {
                print("Handle the error please")
            }
}
        func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
            a.removeAll()
            d.removeAll()
            num.removeAll()
            inProcess.removeAll()
            for contact in contacts {
                a+=[contact.givenName]
                for ContctNumVar: CNLabeledValue in contact.phoneNumbers {
                    let FulMobNumVar  = ContctNumVar.value
                    _ = FulMobNumVar.value(forKey: "countryCode") as? String
                    let MobNumVar = FulMobNumVar.value(forKey: "digits") as? String
                    num+=[MobNumVar!]
                    print("\(contact.givenName) phone number is:\( MobNumVar!)")

                }

            }
            print(a)
            print(num)
            print(a.count)
            let n = a.count
            let res = Float(Float(amount)/Float(n))
            print(res)
            for _ in 1...n
            {
                d+=[(res)]

            }

            print(d)
            for c in a {
                print("selected contacts:\(c):\(res)")


            }

        }

那么如何通过搜索栏选择联系人以及复选框。

0 个答案:

没有答案