簡體   English   中英

如何從ABPeoplepicker委托方法返回之前的兩個viewController

[英]How to go back two viewControllers before, from ABPeoplepicker delegate method

我正在開發一個使用ABPeopleViewController的應用程序,並且我想在用戶最終選擇一個聯系人時,向后移兩個viewcontroller。 這是我到達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;
}

嘗試把這個

[_delegate didReceiveMail:self.mailSelected];

在完成區塊內

[self dismissViewControllerAnimated:YES completion:nil];

在它之前。

(如果這樣不起作用,您可以在maincontroller委托方法上簡單地調用兩次dissmiss,每次關閉都會從堆棧中刪除一個)

[[[self presentingViewController]  presentingViewController] dismissViewControllerAnimated:NO completion:nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM