UIScrollView and presentModalViewController - iphone

I add UITableViewController in UIScrollView. When I call
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Email"];
[picker setMessageBody:currentcelltext isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
MFMailComposeViewController is coming in UIScrollView. So, I can't press cancel and send button.
How to fix it ?

I hope that you set MessageUI.framework in your xcode project..
After you have to set delegate in .h file..
than ,
you have to create one more method..
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}

You might have fixed the issues.
This answer is for those who might come to this post with the expectation of answer.
To fix this you have to use delegation pattern. I assume all the pages in your scrollview are viewcontroller instances and scrollview is subview to viewcontroller.
This answer https://stackoverflow.com/a/626946/451867 can help you to implement delegate pattern in your project,
You can read developer docs for more info - docs

Related

MFMailComposeViewController ModalView crashes the iOS5 application

I have an iOS TabBar Application with tabbarcontroller and navigationcontroller.
In my detail view wich is pushed from my first tab tableviewcontroller i have sharing navigationItem.rightBarButtonItem with email sharing.
I have the following code for this:
- (void)share
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"Send" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Email",nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setMailComposeDelegate:self];
[picker setSubject:#"New theme"];
NSString *emailBody = #"Hi there";
[picker setMessageBody:emailBody isHTML:NO];
[self resignFirstResponder];
picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:picker animated:NO];
[picker release];
}
else{
}
}
}
The app shows me the composing view but when i'm trying to do something with this view (e.g. to pick up the address or to spell something) - app crashes with SIGTRAP.
The app crashes only in iOS5, iOS5.1. In iOS4.2.1 everything works perfect.
What's the problem? Any ideas?
Per the docs, I'd suggest calling [MFMailComposeViewController canSendMail] class method before creating MFMailComposeViewController. I also generally don't have that [self resignFirstResponder] line. I gather you're crashing before your mailComposeController:didFinishWithResult:error method is invoked?
Thank you guys for your help and your time.
It was absolutely insane bug. Project has a cyrillic name. I just renamed it to latin name and now everything works fine. My fault :( Thanks Evgeniy Shurakov for the help.

In App Email View doesn't close - iPhone OS 4

I am having difficulties adding the ability for a user to send a support email to myself (the maker of said app). I have gotten it work almost perfectly however the view doesn't close when you click cancel, or when you click send. Thanks for the help!
Here is the code:
MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
[mail setToRecipients:[NSArray arrayWithObject:#"support#lindahlstudios.com"]];
[mail setSubject:#"Fraction Calculator Lite Support"];
[self presentModalViewController:mail animated:YES];
You're setting self to be the MFMailComposeViewController's delegate. In mailComposeController:didFinishWithResult:error: be sure to call
[self dismissModalViewControllerAnimated:YES];
like so:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You need to implement the delegate method from MFMailComposeViewControllerDelegate.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}

Keyboard not showing after MFMessageComposeViewController

In an iPhone app I have a UITextView and a button, which lets the user send the content of the UITextView as a text message. The code looks like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.body = textView.text;
[self presentModalViewController:picker animated:YES];
Everything works fine, except for when the message is either sent or Cancel is tapped in the MFMessageComposer: The keyboard for the UITextView is not shown anymore, even though the cursor blinks.
I tried a few things, including a [textView resignFirstRepsonder] in both the button code and -viewDidDisappear. [textView becomeFirstResponder] in the MFMessageComposeViewControllerDelegate method or the -viewDidAppear didn't change anything either...
Any ideas?
I had the same issue, and was resigned to accepting fabian's solution, but found that by calling [self dismissModalViewControllerAnimated:NO] and then calling [textView becomeFirstResponder], I was able to make the keyboard reappear. Something about the animation was screwing up the keyboard; looks like a bug in iOS 4.2.
After the view has disappeared, you need to make your view first responder. Add the MFMessageComposeViewControllerDelegate protocol to your header, then use the following:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[self dismissModalViewControllerAnimated:YES];
[self becomeFirstResponder];
}
Happy coding,
Zane
I had a similar problem and was able to fix it by calling becomeFirstResponder after a slight delay:
[textField performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0.01];
The delay trick also solves the problem of missing text cursor after showing an UIAlert right after MFMessageComposeViewController finishes, however the delay needs to be much longer (0.5 sec in my case)
I was not able to find a better solution, so here is my fix:
In
- (void) actionSheet:(UIActionSheet *)actionSheet
willDismissWithButtonIndex:(NSInteger)buttonIndex
I dismiss the Keyboard and in
- (void) actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex`
I present the MFMessageComposeViewController.
In
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result
I don't do [textView becomeFirstResponder] as it doesn't work. Neither does it work in viewDidAppear:. The user has to tap the UITextField again.
Not a very nice solution but the only one I found...
As of iOS 5, here is one workaround. Before you present the MFMessageComposeViewController instance, resign first responder on your UITextView:
[self presentViewController:messageComposer animated:YES completion:NULL];
[textView resignFirstResponder];
Then in the delegate method messageComposeViewController:didFinishWithResult: do this:
[controller dismissViewControllerAnimated:YES completion:^{
[textView performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:0];
}];
This fixed the disappearing keyboard problem for me. Without having to permanently dismiss the keyboard.
This behaviour will not appear if viewController which is shown before modal VC is a child of navigation controller. So solution is to make fake UINavigationController and add your VC controller to nav controller.

iPhone: How to Close MFMailComposeViewController?

I'm having difficulties closing an email message that I have raised.
The email opens nicely, but once it is opened it will not close as the mailComposeController:mailer didFinishWithResult:result error:error handler never gets invoked.
As far as I can tell I have all the bits in place to be able to do this.
Anyone any ideas of what I can look at?
Here is how I raise the email:
-(IBAction)emailButtonPressed
{
NSString *text = #"My Email Text";
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.delegate = self;
[mailer setSubject:#"Note"];
[mailer setMessageBody:text isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
and later in the class I have this code to handle the close (but it never gets called):
-(void)mailComposeController:(MFMailComposeViewController *)mailer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self becomeFirstResponder];
[mailer dismissModalViewControllerAnimated:YES];
}
My header file is defined as:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface myViewController : UIViewController <UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>
Thanks
Iphaaw
You are setting the delegate wrong, the delegate property in MFMailComposeViewController is called mailComposeDelegate, so it should be:
mailer.mailComposeDelegate = self;
Another possible error I can see is calling dismissModalViewControllerAnimated: on mailer - you should send this message to the view controller who presented the mail interface - self in this case:
[self dismissModalViewControllerAnimated:YES];
I wrote "possible error" because it might actually work if iOS routes the message through responder chain, anyway - the documentation says it should be send to presenter.

MFMailComposeViewController does not send mail

I am trying to send mail using MFMailComposeViewController. Everything works, except that mails do not get sent, and I always get MFMailComposeResultFailed.
Any pointers? I am NOT using the simulator, and sending mail does work from my device. I do have a connection (testing via Reachability), and [MFMailComposeViewController canSendMail] returns YES.
No compiler warnings in the project, no crashes...
It was a bug in IOS4.
I had both an Exchange mail account and an old, inactive IMAP account on my phone. Apparently, that leads to problems with iOS4. The mails actually were stuck in the outbox. Once I removed the inactive IMAP account, everything worked as expected.
Some readers might be facing this problem:
Make sure you implement the <MFMailComposeViewControllerDelegate> protocol
Here's the code:
// in TestViewController.h
#interface TestViewController : UIViewController<MFMailComposeViewControllerDelegate>
#end
// in TestViewController.m
#interface TestViewController ()
#end
#implementation
- (void) compose {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello there"];
[picker setToRecipients:#[]];
// Fill out the email body text
NSString *emailBody = #"Hello, sending a message from my app";
[picker setMessageBody:emailBody isHTML:NO];
// use this function. presentModalViewController:... is deprecated
[self presentViewController:picker animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
It's difficult to tell without seeing a code snippet, however you should check the following:
1) you have correctly set the MFMailComposeViewController's delegate and implemented its delegate methods;
2) you have set the mail subject using setSubject:
3) you have set the message body using setMessageBody:isHTML:
and optionally set an attach using addAttachmentData:mimeType:fileName:
4) you have presented to the user your mail compose view controller using something like
[self presentModalViewController:mcvc animated:YES];
Hope this helps.