iPhone, Obj-C, How can I use in app email from an actionsheet button click while using addSubview?

Deadly 提交于 2019-12-20 07:46:22

问题


I found some great example code some months ago to add a compose button to a view to allows emails to be sent within an app...

http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/

However, I want to be able to show the email, have it handled for use with any of my views. I have a standard class / method to show the actionsheet, so I can use it in all my views.

This is the code from another button in my class.

-(UIViewController *)showHelpClickButtonAtIndex:(int)buttonIndex:(UIView *)
      vw:(UIViewController *)vc:(BOOL)useNav:(HelpPage)page{

if (buttonIndex == CommonUIInfoHelpPagesBtnIdx) {
vc = [[HelpViewController alloc] initWithNibName:@"HelpView" 
         bundle:nil onPage:page];
   [vw addSubview:vc.view];
   return [vc autorelease]; 

Heres the example code, without any of my many attempts to make it work..

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:titleText.text];
NSString *emailBody = @"Whatever";
[picker setMessageBody:emailBody isHTML:YES]; 
picker.navigationBar.barStyle = UIBarStyleBlack; 
[self presentModalViewController:picker animated:YES];
[picker release];

Its mainly the MFMailComposeViewController and replace presentModalViewController with addSubview where I'm having problems.

Can anyone point me in the right direction ?


回答1:


According to the docs for MFMailComposeViewController:

To display the view managed by this view controller, you can use any of the standard techniques for displaying view controllers. However, the most common way to present this interface is do so modally using the presentModalViewController:animated: method

The first sentence is telling us that you should be showing the view controller for the mail composer in one of the regular ways; adding the view controller's view as a subview to an existing UIView, if that's what you're trying to do, isn't one of the standard ways Apple want you to use, and so might not work or be unpredictable.

Related to this is Apple's advice that a UIViewController should be responsible for showing a whole part of your UI, not just part of it -- which your approach also seems to go against.

So, the solution is to present the mail composer like a normal view controller would be: modally, or pushed onto a nav stack, or presented as the top view under UIWindow, etc.



来源:https://stackoverflow.com/questions/5110034/iphone-obj-c-how-can-i-use-in-app-email-from-an-actionsheet-button-click-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!