簡體   English   中英

模態UIImagePickerController被關閉時的UIView通知?

[英]UIView notification when modal UIImagePickerController is dismissed?

模態視圖完成關閉后,有沒有辦法調用代碼?

編輯:

抱歉,我之前沒有澄清。 我正在嘗試關閉UIImagePickerController,然后顯示MFMailComposeViewController並將圖像數據附加到電子郵件。 當我嘗試打電話時

[self presentModalViewController: mailController]

之后

[self dismissModalViewController];

我得到這樣的錯誤。

您可以對模式視圖使用委托模式,以通知完成時向誰提出。

MyModalViewController.h:

@protocol MyModalViewControllerDelegate;

@interface MyModalViewController : UIViewController
{
    id<MyModalViewControllerDelegate> delegate;
}

@property (nonatomic, assign) id<MyModalViewControllerDelegate> delegate;

@end


@protocol MyModalViewControllerDelegate
- (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController;
@end

MyModalViewController.m:

@synthesize delegate;

// Call this method when the modal view is finished
- (void)dismissSelf
{
    [delegate myModalViewControllerFinished:self];
}

ParentViewController.h:

#import "MyModalViewController.h"

@interface ParentViewController : UIViewController <MyModalViewControllerDelegate>
{
}

ParentViewController.m:

- (void)presentMyModalViewController
{
    MyModalViewController* myModalViewController = [[MyModalViewController alloc] initWithNibName:@"MyModalView" bundle:nil];
    myModalViewController.delegate = self;
    [self presentModalViewController:myModalViewController animated:YES];
    [myModalViewController release];
}

- (void)myModalViewControllerFinished:(MyModalViewController*)myModalViewController
{
    [self dismissModalViewControllerAnimated:YES];
}

編輯:

我沒有使用過UIImagePickerController ,但是查看文檔,似乎您已經為您完成了大部分代碼,因為現有的UIImagePickerControllerDelegate類具有三個不同的“解雇”委托回調(盡管已棄用了一個)。 因此,您應該使ParentViewController類(無論是ParentViewController類型)都實現UIImagePickerControllerDelegate模式,然后實現這些方法。 盡管每種方法都會做不同的事情(因為您必須在用戶實際選擇圖像時或取消圖像時進行處理),但每種方法最終都會做相同的事情:調用dismissModalViewControllerAnimated:可以關閉選擇器。

您必須以某種方式關閉modalViewController對嗎? UIButton或通過代碼:

- (void)dismissModalViewControllerAnimated:(BOOL)animated

在UIButton的IBAction(例如委托)中或在上面的方法中,調用所需的任何代碼。

我認為尚無特定的通知可以訂閱,以了解關閉動畫的時間……但是。 您可以在提供模態視圖的視圖控制器中實現viewDidAppear: 當我使用(與UIImagePickerController非常相似)ABPeoplePickerNavigationController時,這就是我的工作。

在人員選擇器的回調中,我記得該人員在選擇器中使用了一個實例變量,例如:

- (void)callbackFromModalView:(id)dataFromModalView {
    // remember dataFromModalView as I need it when dismissed
    self.dataFromModalView = dataFromModalView;

    // now initiate dismissal
    [self dismissModalViewControllerAnimated:YES];
}

然后,在您的視圖控制器中,實現以下目標:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (self.dataFromModalView) {
        //...present now view here

        // don't forget to reset this one
        self.dataFromModalView = nil;
    }
}

實際上,您正在使用viewWillAppear:dataFromModalView屬性的組合作為“有關模態視圖的通知已關閉”。

暫無
暫無

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

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