MFMailComposeViewController mailComposeDelegate的完成块语法是否可行?

时间:2012-06-08 01:39:21

标签: objective-c ios objective-c-blocks mfmailcomposeviewcontroller

我想将MFMailComposeViewController mailComposeDelegate属性与完成块语法一起使用,但不确定是否可行。与TWTweetComposeViewController completionHandler属性的工作方式类似的内容:

TWTweetComposeViewController __weak *twee = tweeter;
tweeter.completionHandler = ^(TWTweetComposeViewControllerResult result) {
    // code here
};

我创建MFMailComposeViewController的代码,但后来必须保存引用我的viewController参数,因为这个“通过电子邮件共享”功能不是UIViewcontroller,而是自定义{{1 }。class。

MYSharing

来自MFMailComposeViewControllerDelegateMFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; // more code here _viewController = viewController; picker.mailComposeDelegate = self; [viewController presentModalViewController:picker animated:YES]; 使用mailComposeController:didFinishWithResult:error:来解除模态。

_viewController

不能很好地理解块,是否有一些看起来像这样的语法?

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [_viewController dismissModalViewControllerAnimated:YES];
}

我确实找到了MFMailComposeViewController(BlocksKit)(github上有源代码),但即便如此,语法转换也让我兴奋不已。

2 个答案:

答案 0 :(得分:2)

现在没有MFMailComposeViewController的完成处理程序。

如果要引用呈现MFMailComposeViewController的视图控制器,如下所示,请使用presentViewController属性。

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
    [controller.presentingViewController dismissModalViewControllerAnimated:YES];
}

答案 1 :(得分:0)

为什么不从[self dismissModalViewControllerAnimated:YES];方法拨打MFMailComposeViewControllerDelegate