Swift:从Closing中阻止ABPeoplePickerNavigationController

时间:2015-08-21 21:56:03

标签: ios swift uinavigationcontroller abaddressbook presentviewcontroller

我想找出一种方法,以便在用户按下"取消"在ABPeoplePickerNavigationController中,按钮(我不相信可以删除),视图控制器要么关闭,要么自动重新打开。

例如,给出以下内容:

var picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = self
self.presentViewController(picker, animated: true, completion: nil)

我希望能够做到这样的事情:

if (self.presentedViewController != picker && !userContinuedPastPicker) {
//where userContinuedPastPicker is a boolean set to false 
//in a delegate method called when the user clicks on an a contact 
//(meaning the user didn't press the cancel button but instead clicked on a contact)

    //create and present a UIAlertAction informing the user they must select a contact

    //present picker again
    self.presentViewController(picker, animated: true, completion: nil) 
}

这不起作用;但是,因为if声明赢了"等等"直到用户按下取消按钮或按下联系人。

1 个答案:

答案 0 :(得分:4)

我不确定是否有办法删除取消按钮或阻止其工作,但您可以回复func peoplePickerNavigationControllerDidCancel(_ peoplePicker: ABPeoplePickerNavigationController!)代表来处理按下取消按钮的情况。

我建议而不是立即重新打开拣货员,打开警报告诉用户他们需要选择某人,然后从那里打开它。如果他们取消它可能会感到破碎,并立即打开。

Reference

编辑:
提示警报或拣货员可能需要延迟足够长时间才能关闭前一个拣货员。 dispatch_after