ContactsUI(选择联系人).md

来源:互联网 发布:zookeeper 默认端口 编辑:程序博客网 时间:2024/04/30 14:46

1 CNContactPickerViewController

1.1 Displaying Contacts Properties

1.2 Notifying Delegate

1.3 Predicates For Selecting Contacts

2 实战演练

2.1 源代码

2.2 效果图


1 CNContactPickerViewController

CNContactPickerViewController支持快速选中联系人或联系人的属性,支持单选和多选。

1.1 Displaying Contacts Properties

/// 联系人名片可展示的信息public var displayedPropertyKeys: [String]?

1.2 Notifying Delegate

/// 通过代理控制选择的联系人或联系人属性weak public var delegate: CNContactPickerDelegate?

1.3 Predicates For Selecting Contacts

/// 晒选联系人@NSCopying public var predicateForEnablingContact: NSPredicate? // e.g. emailAddresses.@count > 0/// 可选得联系人@NSCopying public var predicateForSelectionOfContact: NSPredicate? // e.g. emailAddresses.@count == 1/// 可选的联系人属性@NSCopying public var predicateForSelectionOfProperty: NSPredicate? // e.g. (key == 'emailAddresses') AND (value LIKE '*@apple.com')

2 实战演练

2.1 源代码

////  YJContactsUIVC.swift//  Contact////  CSDN:http://blog.csdn.net/y550918116j//  GitHub:https://github.com/937447974/Blog////  Created by yangjun on 16/1/14.//  Copyright © 2016年 阳君. All rights reserved.//import UIKitimport ContactsUI/// ContactsUI显示class YJContactsUIVC: UIViewController, CNContactPickerDelegate {    override func viewDidLoad() {        super.viewDidLoad()    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }    // MARK: - Action    // MARK: CNContactPickerViewController 测试    @IBAction func onClickCNContactPickerViewController(sender: AnyObject) {        // 选择联系人或联系人的属性(如电话号码)        let vc = CNContactPickerViewController()        vc.delegate = self // 根据实现的代理方法指定单选、多选        self.presentViewController(vc, animated: true, completion: nil)    }    // MARK: - CNContactPickerDelegate    func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {        // 单选        print(contact)    }}

2.2 效果图

 


Appendix

Sample Code

Swift

Contacts Framework Reference

CNContactPickerViewController Class Reference

Revision History

时间 描述 2016-01-20 博文完成

CSDN:http://blog.csdn.net/y550918116j

GitHub:https://github.com/937447974/Blog

0 0
原创粉丝点击