ContactsUI(修改联系人)
2016-01-20 14:04
393 查看
CNContactPickerViewController
Required Keys
Initializing View Controllers
Displaying Contact Properties
Notifying Delegate
Contact Store
Customizing Contact Card
Highlighting a Property
实战
源代码
效果图
GitHub:https://github.com/937447974/Blog
Required Keys
Initializing View Controllers
Displaying Contact Properties
Notifying Delegate
Contact Store
Customizing Contact Card
Highlighting a Property
实战
源代码
效果图
1 CNContactPickerViewController
CNContactPickerViewController可以显示一个联系人的相关信息、创建联系人或修改联系人。1.1 Required Keys
/// 获取联系人使用的描述符 public class func descriptorForRequiredKeys() -> CNKeyDescriptor
1.2 Initializing View Controllers
/// 通过已有联系人初始化CNContactPickerViewController public convenience init(forContact contact: CNContact) /// 未知联系人初始化CNContactPickerViewController public convenience init(forUnknownContact contact: CNContact) /// 新建联系人初始化CNContactPickerViewController public convenience init(forNewContact contact: CNContact?)
1.3 Displaying Contact Properties
/// 联系人 public var contact: CNContact { get } /// 所属分组 public var parentGroup: CNGroup? /// 所属集合 public var parentContainer: CNContainer? /// 联系人显示的名称 public var alternateName: String? /// 相关信息 public var message: String? /// 可显示的属性 public var displayedPropertyKeys: [AnyObject]?
1.4 Notifying Delegate
/// 代理控制可显示属性,及获取修改后的联系人 weak public var delegate: CNContactViewControllerDelegate?
1.5 Contact Store
/// 联系人存储库 public var contactStore: CNContactStore?
1.6 Customizing Contact Card
/// 能否修改数据 public var allowsEditing: Bool // YES by default /// 是否显示打电话、发短信等按钮 public var allowsActions: Bool // YES by default /// 是否显示联系人的关联联系人 public var shouldShowLinkedContacts: Bool // NO by default
1.7 Highlighting a Property
/// 属性高亮 public func highlightPropertyWithKey(key: String, identifier: String?)
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 UIKit import ContactsUI /// ContactsUI显示 class YJContactsUIVC: UIViewController, CNContactViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } // MARK: - Action // MARK: CNContactViewController 测试 @IBAction func onClickCNContactViewController(sender: AnyObject) { // 创建或修改联系人 let vc = CNContactViewController(forNewContact: nil) vc.delegate = self self.navigationController?.pushViewController(vc, animated: true) } // MARK: - CNContactViewControllerDelegate func contactViewController(viewController: CNContactViewController, shouldPerformDefaultActionForContactProperty property: CNContactProperty) -> Bool { print(__FUNCTION__) print(property) return true } func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) { viewController.navigationController?.popViewControllerAnimated(true) print(__FUNCTION__) print(contact) } }
2.2 效果图
Appendix
Sample Code
SwiftRelated Documentation
ContactsUI Framework ReferenceRevision History
时间 | 描述 |
---|---|
2016-01-20 | 博文完成 |
Copyright
CSDN:http://blog.csdn.net/y550918116jGitHub:https://github.com/937447974/Blog
相关文章推荐
- ssm+easyui(框架的搭建)
- 转 UCGUI字体解释
- android query的用法
- UITableView取消某一个cell的分割线
- 给 UIButton、UILabel添加下划线
- .net邮件错误 :The specified string is not in the form required for a subject.
- SQL Server 2016 查询存储(Query Store)示例
- SQL Server 2016 查询存储(Query Store)示例
- x-requested-with 判断是否是Ajax异步请求
- 486E - LIS of Sequence(LIS)
- ANT build.xml文件详解(一)
- OncePerRequestFilter
- Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
- 从客户端(XML)中检测到有潜在危险的 Request.Form 值。
- Django数据库queryset操作
- Access restriction: The type BASE64Encoder is not accessible due to restrict
- UIview需要知道的一些事情:setNeedsDisplay、setNeedsLayout
- 黑马程序员——iOS 开发学习---UIPickerView控件的应用
- 用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本
- 构建轻量级的Table View注意事项[UIKit]