0

私はABPeopleViewControllerを使用するアプリを開発していますが、ユーザーが連絡先の選択を完了したら、前に2つの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;
}
4

2 に答える 2

0

これを入れてみてください

[_delegate didReceiveMail:self.mailSelected];

の完了ブロック内

[self dismissViewControllerAnimated:YES completion:nil];

その前に。

(それが機能しない場合は、メインコントローラーのデリゲートメソッドでdissmissを2回呼び出すだけで、各dismissによってスタックから1つが削除されます)

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