gpt4 book ai didi

ios - Swift:编辑 ABPersonViewController

转载 作者:可可西里 更新时间:2023-11-01 02:19:35 25 4
gpt4 key购买 nike

我正在尝试设置我的应用程序,以便当从 ABPeoplePickerNavigationController 中打开特定联系人时,在 ABPersonViewController 中,右上角有一个编辑按钮角落。

我知道以前在这里问过与此非常相似的问题,但我已经逐一查看了。也许部分是因为它们适用于旧版本的 iOS,或者因为大多数是在 Objective-C 中,或者由于我自己的无知,我一直无法解决这个问题。

这是我的代码:

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecord!) -> Bool {

/*let controller = ABPersonViewController()
controller.displayedPerson = person
controller.allowsEditing = true
controller.editing = true
controller.personViewDelegate = self
peoplePicker.pushViewController(controller, animated: true)*/

let picker = ABNewPersonViewController()
picker.newPersonViewDelegate = self
picker.displayedPerson = person
picker.navigationItem.title = "edit contact"
self.navigationController?.pushViewController(picker, animated: true)

return false
}

注释代码是我之前看到这个问题的代码:iOS7 - ABPersonViewController, editing mode

同样,我想要做的就是在顶部添加编辑按钮,以便用户可以选择来编辑联系人,但是 ABPersonViewController 应该在编辑模式下打开。

感谢任何帮助,如果这很乏味,我很抱歉。

最佳答案

这应该有效:

// iOS 8 and later
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!) {
self.pushViewControllerWithPerson(person)
}

// Prior iOS 8
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecord!) -> Bool {
self.pushViewControllerWithPerson(person)
return false
}

func pushViewControllerWithPerson(person: ABRecord) {
let controller = ABPersonViewController()
controller.displayedPerson = person
controller.allowsEditing = true
controller.personViewDelegate = self
self.navigationController?.pushViewController(controller, animated: true)
}

注意:
peoplePickerNavigationController(peoplePicker:shouldContinueAfterSelectingPerson:) 在 iOS 8 中已弃用。因此此 iOS 版本后不再调用此方法。
peoplePickerNavigationController(peoplePicker:didSelectPerson:) 应该改用。

关于ios - Swift:编辑 ABPersonViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31775748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com