如何从人员选择器委托方法返回两个视图控制器

Posted

技术标签:

【中文标题】如何从人员选择器委托方法返回两个视图控制器【英文标题】:How to go back two viewControllers before, from ABPeoplepicker delegate method 【发布时间】:2012-07-20 01:36:33 【问题描述】:

我正在开发一个使用 ABPeopleViewController 的应用程序,我想在用户最终选择联系人时,向后退两个视图控制器。 这是我到达 ABPeoplePickerNavigationController 的方式: 点击主视图控制器的按钮 --> 加载模态(对话框)视图控制器 --> 点击模态视图控制器的按钮 --> 加载 ABContacts。

我正在模态视图中实现 ABContacts 的委托,而该委托又在主视图控制器中有一个委托。

我想从 ABPeoplePicker 委托方法返回到主视图控制器。

希望这能理解并且有人可以帮助我,我没有找到这样的东西。

我的 MainViewController.h:

@protocol ModalViewDialogDelegate

- (void)didReceiveMail:(NSString *)mail;

@end

@interface SetUpViewController : UIViewController<UITextFieldDelegate, ModalViewDialogDelegate>

//...

我的 MainViewController.m:

  //...
  - (void)didReceiveMail:(NSString *)mail

  [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
  //...

我的 ModalView.h:

#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

@protocol ModalViewDialogDelegate;

@interface DialogViewController : UIViewController<ABNewPersonViewControllerDelegate, ABPeoplePickerNavigationControllerDelegate>
   id<ModalViewDialogDelegate> delegate;


@property (nonatomic, assign) id<ModalViewDialogDelegate> delegate;
@property (nonatomic, retain) NSString * mailSelected;
//...

我的 modalView.m:

 - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController  *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier

    //...here i get the email person property and then i want to go backwards to the main view controller, not the modal.

    [self dismissViewControllerAnimated:YES completion:nil];

    //don't know if it's ok like this, because in the implementation also dismiss presented viewcontroller.
    [_delegate didReceiveMail:self.mailSelected];

    return NO;

return YES;

【问题讨论】:

【参考方案1】:

试试这个

[_delegate didReceiveMail:self.mailSelected];

在完成块内

[self dismissViewControllerAnimated:YES completion:nil];

在它之前。

(如果这不起作用,您可以简单地在主控制器委托方法上调用两次 dissmiss,每次关闭将从堆栈中删除一个)

【讨论】:

非常感谢!!它通过在委托方法中调用两次dismissModalViewController来工作!【参考方案2】:
[[[self presentingViewController]  presentingViewController] dismissViewControllerAnimated:NO completion:nil];

【讨论】:

以上是关于如何从人员选择器委托方法返回两个视图控制器的主要内容,如果未能解决你的问题,请参考以下文章

未调用 iOS 13 UIPanGestureRecognizer 选择器

调用委托方法后执行选择器

是否有与 Facebook 好友一起使用的人员选择器视图控制器?

如何自定义选择器视图

ios入门笔记(使用日期选择器)

从视图控制器设置 SKScene 委托,未找到委托