Swift:防止ABPeoplePickerNavigationController关闭

我想找出一种方式,以便如果用户在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语句在用户按下取消按钮或按下联系人之前不会“等待”。


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

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

参考

编辑:
提示警报或选取器可能需要延迟足够长的时间,以便前一个选取器关闭。 dispatch_after

链接地址: http://www.djcxy.com/p/87589.html

上一篇: Swift: Prevent ABPeoplePickerNavigationController from Closing

下一篇: Confused about GCM Token updation process