2012-07-20 73 views
0

我正在開發一個應用程序,它使用ABPeopleViewController,並且我想當用戶敲定選擇聯繫人時,向後退回兩個viewcontroller。 以下是我如何到達ABPeoplePickerNavigationController: 點擊主視圖控制器的按鈕 - >加載模態(對話框)視圖控制器 - >點擊模態視圖控制器的按鈕 - >加載ABContacts。如何從ABPeoplepicker委託方法之前返回兩個viewControllers

我在模態視圖中實現了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; 
} 

回答

0

嘗試把這個

[_delegate didReceiveMail:self.mailSelected]; 

[self dismissViewControllerAnimated:YES completion:nil]; 

它之前完成塊內。

(如果不工作,你可以簡單地調用dissmiss兩次對你maincontroller委託方法,每個駁回將從堆棧中刪除一個)

+0

非常感謝您!它通過在委託方法中調用dismissModalViewController兩次來工作! – sheinix 2012-07-20 02:03:35

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