Swift:从Closing中阻止ABPeoplePickerNavigationController

Ran*_*oms 7 uinavigationcontroller abaddressbook ios presentviewcontroller swift

我想找出一种方法,这样,如果用户按下"取消"按钮(我认为不能删除)ABPeoplePickerNavigationController,视图控制器要么不关闭,要么自动重新打开.

例如,给出以下内容:

var picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = self
self.presentViewController(picker, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

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

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) 
}
Run Code Online (Sandbox Code Playgroud)

这不起作用; 但是,因为if语句不会"等待",直到用户按下取消按钮或按下联系人.

est*_*ing 4

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

我建议不要立即重新打开选择器,而是打开一个警报,告诉用户他们需要选择某人,然后从那里重新打开它。如果他们取消并立即重新打开,可能会感觉很糟糕。

参考

编辑:
呈现警报或选择器可能需要延迟足够长的时间才能关闭前一个选择器。调度_之后