我之前问过一个关于同一问题的问题,解决方案有效,但它不是兼容 iOS 4.3 的解决方案,我认为我的设计不正确。
现在,当我按下按钮时,我想在我的 RootView(Controller) 顶部将 MFMailComposeView(Controller) 显示为模式视图。而不是让它成为委托,我想做一个简单的 NSObject 来实现协议。谁也能够在 RootViewController 中显示 MFMailComposeView(Controller)。
我正在尝试这种设计/解决方案,它会给我带来内存分配/访问问题。
RootViewController.m:
- (IBAction)tapExportButton:(id)sender
{
SendMailController *sendMailController = [[SendMailController alloc]initWithParentViewController:self];
[sendMailController openMailDialog];
[sendMailController release];
}
发送邮件控制器.h
@interface SendMailController : NSObject <MFMailComposeViewControllerDelegate>
- (id)initWithParentViewController:(UIViewController *)parentViewController;
- (void)openMailDialog;
@property (retain, nonatomic) UIViewController* parentViewController;
@end
发送邮件控制器.m
#import "SendMailViewController.h"
@implementation SendMailController
@synthesize parentViewController = _parentViewController;
- (id)initWithParentViewController:(UIViewController *)parentViewController
{
if (self=[super init]) {
self.parentViewController = parentViewController;
}
return self;
}
- (void) dealloc
{
self.parentViewController = nil;
[super dealloc];
}
- (void)openMailDialog
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
...
mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[self.parentViewController presentModalViewController:mailer animated:YES];
[mailer release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
...
// Remove the mail view
[controller.parentViewController dismissModalViewControllerAnimated:YES];
}
@end
当我在委托方法中设置断点时,它已经在此之前崩溃了。与邮件程序(MFMailComposeViewController)的委托属性有关吗?