ios - 无法关闭 CNContactViewController

标签 ios swift uiviewcontroller uinavigationcontroller uinavigationbar

我正在尝试让用户创建一个新联系人。虽然我有屏幕提示用户输入他的所有详细信息,但顶部没有导航栏(就像默认的 Apple Contacts 应用程序中一样)。没有办法退出现场。我在 swift 2.0 和 Xcode 7.3 中使用 ContactUI 框架。这是代码:

// create a new contact
    let createNewActionHandler = {(action: UIAlertAction) -> Void in
        let newContact = CNMutableContact()

        let contactPicker = CNContactViewController(forNewContact: newContact)
        contactPicker.delegate = self
        contactPicker.navigationController?.setToolbarHidden(false, animated: false)
        self.presentViewController(contactPicker, animated: true, completion: nil)

    }

这是我想要得到的: Apple Default

这是我拥有的: What I have

我正在从选项卡 View Controller 中的操作表启动新的联系人 View Controller 。我尝试将选项卡嵌入导航 View Controller 中,但没有效果。我什至尝试设置 navController 的 setToolbarHidden 属性,但没有帮助。

感谢您的帮助。我在其他论坛上看到了这个问题,但他们没有帮助。

最佳答案

您必须将 contactViewController 嵌入到 UINavigationController 和实现委托(delegate)方法。

let createNewActionHandler = {(action: UIAlertAction) -> Void in
    let newContact = CNMutableContact()

    let contactPicker = CNContactViewController(forNewContact: newContact)
    contactPicker.delegate = self
    let navigation = UINavigationController(rootViewController: contactPicker)
    self.presentViewController(navigation, animated: true, completion: nil)

}


//MARK: - Delegate

  func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
      viewController.dismissViewControllerAnimated(true, completion: nil)
  }

  func contactViewController(viewController: CNContactViewController, shouldPerformDefaultActionForContactProperty property: CNContactProperty) -> Bool {
      return true
  }

关于ios - 无法关闭 CNContactViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37390406/

相关文章:

ios - 在 iOS swift 中使用多点连接

安卓和 iOS : How to develop for both?

ios - 如何更改角标(Badge)计数?

ios - 在 Swift 中从其 UIViewController 访问 UIView

ios - 在 ViewController 中添加两个文本字段并在另一个 ViewController 中显示它

ios - 如何在 UIViewController 中添加自定义 subview 的多个实例

ios - 如何等到 alamofire 图像请求完成

ios - 获取任何 AudioPlayer 来传输或播放音乐

ios - pList IOS Swift 中的数据是无序的

swift - 具有多个数组的 TableView segue