您可以使用模式视图的委托模式来通知完成后呈现的模式。
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
类(不管那是什么)实现UIImagePickerControllerDelegate
模式,然后实现这些方法。虽然每种方法都会做不同的事情(因为您必须在用户实际选择图片或取消图片时处理),但每种方法最后都会做同样的事情:致电dismissModalViewControllerAnimated:
关闭选取器。
看到我的答案更新。 – 2010-09-17 17:33:34