Swift:编辑ABPersonViewController

时间:2015-08-02 19:28:10

标签: ios swift contacts abpeoplepickerview

我正在尝试设置我的应用,以便在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在编辑模式下打开。

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

1 个答案:

答案 0 :(得分:1)

这应该有效:

$query_login = mysql_query("SELECT * FROM users WHERE
  username='".mysql_escape_string($_POST['username'])."' AND
 password='".mysql_escape_string($_POST['password'])."'");

$result = mysql_query($query_login);

$user = mysql_fetch_array($result);

if(mysql_num_rows($result) == 1) {
    setcookie('login', $user['user_id'], time() + (60*60*24*1000);
    header('Location:account.php');
}   

注意:
iOS 8中不推荐使用// 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) } 。因此,此iOS版本不会调用此方法 应该使用peoplePickerNavigationController(peoplePicker:shouldContinueAfterSelectingPerson:)代替。