【问题标题】:IOS Swift CNContactViewController Navigation Bar Not Showing UINavigation ControllerIOS Swift CNContactViewController 导航栏不显示 UINavigation 控制器
【发布时间】:2017-11-02 03:27:18
【问题描述】:

我一直在研究这个问题,但无法解决任何问题。 我有一个视图控制器,它有效地站在主故事板上。在该视图控制器内部,当发生将联系人类型传递给该操作的特定操作时。

该操作为传递的联系人打开一个新的联系人视图控制器,并允许用户根据 CNContactViewController 与联系人进行交互。 一旦用户完成了联系人,它将关闭,因为 didCompleteWith 方法,但是没有办法退出联系人控制器,而不实际创建联系人。

//change to new contact screen
let con = CNMutableContact()
con.givenName = familyComponents[0]
con.familyName = familyComponents[1]

let newEmail = CNLabeledValue(label: "Personal", value: objectComponents[2] 
as NSString)
con.emailAddresses.append(newEmail)
con.phoneNumbers.append(CNLabeledValue(
label: "Home", value: CNPhoneNumber(stringValue: objectComponents[3])))
let newScreen = CNContactViewController(forUnknownContact: con)
newScreen.message = "Made using  app"
newScreen.contactStore = CNContactStore()
newScreen.delegate = self
newScreen.allowsActions = true
let navigationController = UINavigationController(rootViewController: 
newScreen)
self.present(navigationController, animated: true, completion: nil)

从navigationItems到navigationItems我都试过了,在我看来导航栏就在那里,因为可以用这行代码改变它的半透明性:

navigationController.navigationBar.isTranslucent = true

以下方法:

func contactViewController(_ viewController: CNContactViewController, 
didCompleteWith contact: CNContact?) {
    viewController.dismiss(animated: true, completion: nil)
    inContact = false
}
func contactViewController(_ shouldPerformDefaultActionForviewController: 
CNContactViewController, shouldPerformDefaultActionFor property: 
CNContactProperty) -> Bool {
    return false
}

任何建议都将不胜感激,我已经为这个问题苦苦挣扎太久了。 谢谢!

已解决: 让它工作。原来这是苹果框架中的一个错误。为了解决这个问题,我只是将它从未知联系人切换到新联系人,显然没有这个错误。 部分新代码:

let newScreen = CNContactViewController(forNewContact: con)
newScreen.delegate = self
let navigationController = UINavigationController(rootViewController: newScreen)
self.present(navigationController, animated: true, completion: nil)

谢谢

【问题讨论】:

  • 在没有显示导航之后还是之前?
  • 在完成之前,没有显示导航栏,除了完成之外,我还需要其他方法来取消。

标签: ios swift uinavigationcontroller cncontactviewcontroller


【解决方案1】:

你可以试试这段代码吗

let con = CNMutableContact()
con.givenName = familyComponents[0]
con.familyName = familyComponents[1]

let newEmail = CNLabeledValue(label: "Personal", value: objectComponents[2] 
as NSString)
con.emailAddresses.append(newEmail)
con.phoneNumbers.append(CNLabeledValue(
label: "Home", value: CNPhoneNumber(stringValue: objectComponents[3])))
let unkvc = CNContactViewController(forUnknownContact: con)

                                unkvc.delegate = self
                                unkvc.allowsEditing = true
                                unkvc.allowsActions = true
                                unkvc.title = "Edit Contact"

    self.navigationController?.isNavigationBarHidden = false

    self.navigationController?.navigationItem.hidesBackButton = true

    self.navigationController?.pushViewController(unkvc, animated: false)

【讨论】:

  • 谢谢!我的问题在于当前 navigationController 的隐藏 NavigationBar
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多