0

我正在开发一个使用 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];
  //...

我的模态视图.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;
}
4

2 回答 2

0

试着把这个

[_delegate didReceiveMail:self.mailSelected];

在完成块内

[self dismissViewControllerAnimated:YES completion:nil];

在它之前。

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

于 2012-07-20T01:43:47.017 回答
0
[[[self presentingViewController]  presentingViewController] dismissViewControllerAnimated:NO completion:nil];
于 2016-02-29T07:34:20.513 回答