簡體   English   中英

CNContactViewController取消按鈕不起作用

[英]CNContactViewController Cancel Button Not Working

我正在嘗試使用內置的新聯系人UI,並使用取消按鈕獲得意外行為。 下面的代碼工作並調出新的聯系人屏幕,但取消按鈕將僅清除未從新聯系人屏幕取消的屏幕條目。 在內置聯系人應用程序點擊取消返回到聯系人列表屏幕。 我想取消按鈕關閉窗口。

@IBAction func newTwo(sender: AnyObject) {
    AppDelegate.getAppDelegate().requestForAccess { (accessGranted) -> Void in
        if accessGranted {
            let npvc = CNContactViewController(forNewContact: nil)
            npvc.delegate = self
            self.navigationController?.pushViewController(npvc, animated: true)
         }
    }

}

你實現了CNContactViewControllerDelegate方法嗎? 這是文檔的鏈接

例如:

 func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {

    self.dismissViewControllerAnimated(true, completion: nil)
}

更好的解雇方法是檢查聯系人是否為零,然后解雇。 如果您已從導航控制器推動視圖控制器,則忽略不起作用。 您可能必須執行以下操作:

func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
  if let contactCreated =  contact
  {

  }
  else
  {
    _ = self.navigationController?.popViewController(animated: true)
  }
}

它使用以下代碼為我工作:

斯威夫特3

func contactViewController(_ vc: CNContactViewController, didCompleteWith con: CNContact?) {
    vc.dismiss(animated: true)
}

我也改變了調用控制器的方式:

代替:

self.navigationController?.pushViewController(contactViewController, animated: true)

解決方案是:

self.present(UINavigationController(rootViewController: contactViewController), animated:true)

我使用Matt Neuburg編寫的示例代碼Programming-iOS-Book-Examples找到了解決方案:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM