I have a common action sheet (in NSObject class) that is called from multiple classes. One of the actions is launching email. Everything works great when called from the first NIB loaded. However, after I switch NIBs using modal views, the email (its own modal view) will not appear in any of these (but all other actions work fine). I presume it is because they are modal views and not the viewController called by the App's delegate. I presume the "rootViewController" below is the issue. I'm stuck. Help appreciated.
-(void)SendEmail {
// all this NSObject to send emails
rootViewController = (UIViewController*)[(AppDelegate*)[[UIApplication sharedApplication] delegate] viewController];
// compose
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
//controller.mailComposeDelegate = self;
controller.mailComposeDelegate = self;
//format message
NSArray *recipientsArray = [[NSArray alloc] initWithObjects:#"support#A___.com", nil]; // email recipients must be in an array
[controller setToRecipients:recipientsArray];
[controller setSubject:[NSString stringWithFormat:#"A question about %#",stuff]];
//[controller setMessageBody:outputMutString isHTML:YES];
//send
if (controller) {
NSLog(#"email controller");
[rootViewController presentModalViewController:controller animated:YES];
}
}
I founded that the problem is the place where I'm calling the showNextView. I have another interface webService where i communicate with server and parse xml. When the parsing is finished with method parserDidEndDocument I'm calling the delegate method where is changed the view and show modal view. But when i call all that methods it will return to endDocument and xmlParseChunk and so on. It looks like the parserDidEndDocument is not realy the last method and somehow it mess with navigationcontroler. When i call the method for showig nextView with button it works.
The code which is working on button. In delegate method called from parserDidEndDocument is not working correct.
-(void)showNextView
{
UIViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:#"vcTrabantInfo"];
[[nextView navigationController] setNavigationBarHidden:NO animated:NO];
[[self navigationController] pushViewController:nextView animated:YES];
UIViewController *picker = [[UIViewController alloc] init];
[picker setModalPresentationStyle:UIModalPresentationFormSheet];
[[self navigationController] presentModalViewController:picker animated:YES];
}
As usualy the problem was between keyboard and seat. The problem was that my modal views haven't been dismissed before i call another modal view :). So keep in mind that all is done in viewDidDisappear.
i'm new with iPhone developpement and i try to lunch a UIviewController when the user pressed a button witch will allow the user too send an email.
So my AppControler is a NSObject witch contains a UIWindow and a UIViewController* myViewController
When i detect the click on the button i create this:
MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] initWithNibName:#"MainWindow"
bundle:nil];
picker.mailComposeDelegate = myViewController;
... set the mail
and then when i try to present the view controller with this
[myViewController presentModalViewController:picker animated:YES];
[picker release];
Nothing append..
i know it's simple but i cant figured it out what is wrong.
thanks
Try using:
[self presentModalViewController:picker animated:YES];
As #dannywartnaby mentioned unless myViewController points to the current view controller (self) it won't work.
MFMailComposeViewController displaying only bar at the top of the screen with the cancel and send buttons. Code for landscape:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"In app email..."];
[controller setMessageBody:#"...Hi, all...." isHTML:NO];
//[self presentModalViewController:controller animated:YES];
controller.view.frame = CGRectMake(0,0,480,320);
[self.view addSubview:controller.view];
[controller release];
What is problem?
i've ever seen this problem before, as far as i know, you shouldn't replace the presentModalViewController method with addsubview.
I was getting this behavior, as well as the modal view coming in from the side and the modal view was stopping a quarter of the way through presenting.
In my app I had many view controllers stacked with addSubview:. I don't know why but it worked to present the modal view from the bottom view controller. I did something like this:
[((FirstViewController*)[UIApplication sharedApplication].delegate).firstViewControllerInstance sendEmailwithInfo];
Hope that helps! And maybe someone can give some insite as to why it was happening.
I've spent the past two days just trying to enable the sending of email from within my app. Hoping one of the smart folks on here can help me out.
presentModalViewController doesn't work for me (just crashes the app with no explanation as to why), so I'm forced to add the view of MFMailComposeViewController. Here's my attempt:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"test subject"];
[controller setMessageBody:#"this is the message body" isHTML:NO];
// [self presentModalViewController:controller animated:YES]; //this crashes the app
//so I try this instead:
controller.view.frame = CGRectMake(0,0,480,320);
[self.view addSubview:controller.view];
[controller release];
What gets added to the screen is the subject bar only, with cancel and send buttons. None of the text fields (To:, Cc:, Subject, body) are displayed. Why aren't they a part of MFMailComposeViewController's view, and how can I display them?
Honestly, you should be using presentModalViewController. Rather than force your way around the SDK, consider debugging the crash. Turn on the debugger and see if there are any exceptions logged in the console. Check for crash logs, etc...
Also, make sure that self is a proper delegate and a UIViewController subclass.
I 've solved this problem:
try NOT this:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
but THIS:
MFMailComposeViewController *mailComposeViewController = [MFMailComposeViewController new];
You should instead try:
[[self navigationController] presentModalViewController...];
Since that's the proper way to present it. Trying to add its view manually is unfortunately utterly incorrect and will never work.
Well I have determined that one must create a dummy view controller otherwise the darn thing won't slide in.
I create a class called Sys_Mail that is a #interface Sys_Mail : UIViewController <MFMailComposeViewControllerDelegate>
and then i create basically a root view view controller. I wrestled with portrait/landscape for hours but determined that if you attach the view controller to the top level view (which contains my landscape transform) then it slides in as a landscape window. There is just one visual glitch, the parent window gets moved around for a few seconds while the new window slides in, this is a side effect of the landscape transform doing odd things to the parent....
in order to get landscape orientation on the sliding window you must declare a method in your Sys_Mail class that handles the autorotate message:
//=======================
// shouldAutorotateToInterfaceOrientation
//=======================
// see if this ever gets called for the view controller
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
if (TRACE) printf ("shouldAutorotateToInterfaceOrientation\n");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); // or whatever orientation is needed
}
the variable gMasterView refers to my top level view (that has the landscape transform and is attached to the window). Subviews don't seem to work, view controllers are awful THEY ARE MORE DESIGN PATTERN CRAP. I want total control of my views not some microsoft MFC type crud!
Sys_Mail* g_root_vc;
if (g_root_vc == nil) {
// create an empty view controller so we have something to work with
g_root_vc = [[Sys_Mail alloc] init];
g_root_vc.view = (UIView*) gMasterView;
}
so this
I have the same crash and finally I can fix it by sending presentModalViewController message to [self navigationController].
Here is my code:
// Create the Mail composer view controller
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
// Set the view controller delegate
controller.mailComposeDelegate = self;
// Set recipients, if you want
[controller setToRecipients:recipients];
// Set subject, if you want
[controller setSubject:#"The subject"];
// Set message body, if you want
[controller setMessageBody:#"The message body" isHTML:YES]; // isHTML -> YES/NO depending the message body
// Present the view controller
[[self navigationController] presentModalViewController:controller animated:YES];
// Memory management
[controller release];
I hope this can help!