【问题标题】:Unable to dismiss CNContactViewController无法关闭 CNContactViewController
【发布时间】:2016-09-20 07:11:18
【问题描述】:

我正在尝试让用户创建一个新联系人。虽然我有屏幕提示用户输入他的所有详细信息,但顶部没有导航栏(就像默认的 Apple 联系人应用程序中一样)。没有办法退出现场。我在 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

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

感谢您的帮助。我看到其他论坛提出的问题,但他们没有帮助。

【问题讨论】:

    标签: ios swift uiviewcontroller uinavigationcontroller uinavigationbar


    【解决方案1】:

    由于您在当前活动控制器的顶部呈现contactPicker viewcontroller,因此您将无法访问导航栏,因为视图已完全呈现,如果您想拥有Apple 联系人应用程序中的按钮,您需要将呈现的viewcontroller 嵌入UINavigationController ,并添加左右栏按钮项。

    请参阅以下演示相同的苹果示例。 https://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/Listings/Classes_RecipeAddViewController_m.html

    【讨论】:

      【解决方案2】:

      视图控制器必须嵌入在 UINavigationController 中,您应该推送或显示视图控制器:

      navigationController?.pushViewController(contactPicker, animated: true)
      

      而不是呈现视图控制器

      【讨论】:

        【解决方案3】:

        您必须将 contactViewController 嵌入到 UINavigationController 并实施委托方法。

        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
          }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-03-23
          • 1970-01-01
          • 2018-06-18
          • 2010-11-08
          • 2013-02-24
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多