Apple provides the code to use MFMailComposeViewController.but it uses
- (IBAction)buttonPressed
{
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc]init];
controller.mailComposeDelegate = self;
[controller setSubject:#"In app email..."];
[controller setMessageBody:#"...a tutorial from mobileorchard.com" isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
}
by default it uses bottom UP transition.suppose if i want to use following, it gives wrong
ouput.can i use other add subview like that instead of presentModalViewController
{
UIViewAnimationTransition trans = UIViewAnimationTransitionFlipFromRight;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition:trans forView: [self view] cache: YES];
[self presentModalViewController: controller animated:YES];
[UIView commitAnimations];
}
it works correctly for other view controller,but it did not work in MFMailComposeViewController any help please?
hi i have done like this,but current view controller flips, and then composer comes from
bottom..?will you help?
- (IBAction)clickedMailButton:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mcontroller = [[MFMailComposeViewController alloc]init];
//[mcontroller setSubject:#"My Pocket Schedule"];
[mcontroller setTitle:#"New Message"];
[mcontroller setMessageBody:#"Check out My Pocket Schedule in the iTune Store" isHTML:NO];
mcontroller.mailComposeDelegate = self;
UIViewAnimationTransition trans = UIViewAnimationTransitionFlipFromRight;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition:trans forView: [self view] cache: YES];
[self presentModalViewController:mcontroller animated:YES];
[UIView commitAnimations];
[mcontroller release];
}
Use the modalTransitionStyle property:
MFMailComposeViewController *mcontroller = [[MFMailComposeViewController alloc] init];
[mcontroller setTitle:#"..."];
[mcontroller setMessageBody:#"..." isHTML:NO];
mcontroller.mailComposeDelegate = self;
mcontroller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mcontroller animated:YES];
[mcontroller release];
Try
presentModalViewController:withTransition:
Related
I have the following problem. I want to go from a view to another view, not with a button, but writing code. I have a view in which there are, among other things, some buttons. When I press one of them runs an if - else. From else I want to go to another view.
I have tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view insertSubview:gOver.view atIndex:0];
and this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view removeFromSuperview];
[self.view addSubview:gOver.view];
but nothing worked. Any ideas ?
i also tried this
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
[self.view setHidden:YES];
[self.navigationController pushViewController:gOver animated:NO];
throws exeption on
[self presentModalViewController:gOver animated:YES];
[self.view insertSubview:gOver.view atIndex:0];
[self.view addSubview:gOver.view];
Thanks in advance
DonĀ“t call [self.view removeFromSuperview]; which may cause your viewController to be deallocated, when using presentModalViewController it covers your view:
GameOverViewController *gOver = [[GameOverViewController alloc]initWithNibName:#"GameOverViewController" bundle:nil];
// gOver.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gOver animated:YES];
If you need to hide your current view then use: [self.view setHidden: YES];
"I want to go from a view to another view, not with a button, but writing code." - did you refer this to push in storyboard or did you mean that you din't want it in a button action?
The above code works fine :
-(IBAction)buttonAction:(id)sender
{
GameViewController *game = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil];
game.modalTransitionStyle = UIModalTransitionStylePartialCurl ;
[self presentModalViewController:game animated:YES];
}
And hope that you doing n iPhone app and not an iPad one, in which case you need to use popOver instead of modalView
How do I add UISplitView after clicking on the SingleView application? Clearly when the user has successfully logged in then they will see splitView? How is it possible? Please give me guidelines or if possible then code for that because I'm new to iPhone development and I haven't more knowledge for it?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.90];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.navigationController.view cache:YES];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
if (!masternavigationController) {
masternavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
}
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
if (!splitViewController) {
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:masternavigationController, detailViewController, nil];
UIViewController *view_controller = (UIViewController *)[navigationController.viewControllers objectAtIndex:([navigationController.viewControllers count]-1)];
[masternavigationController.navigationBar setHidden:TRUE];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[splitViewController.view setBounds:CGRectMake(0, 0, 1024, 748)];
[splitViewController.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[view_controller.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
view_controller.view.tag = 17;
[UIView animateWithDuration:1.05 animations:^{navigationController.view.alpha = 0.0;} completion:^(BOOL finished){
[navigationController.view addSubview:splitViewController.view];
[UIView animateWithDuration:1.00 animations:^{navigationController.view.alpha = 1.0;} completion:nil];}];
rootview *rtview = [[rootview alloc] initWithNibName:#"rootview" bundle:nil];
rtview.delegate = detailViewController;
[detailViewController.view addSubview:rtview.view];
flag = YES;
[rtview release];
}
[UIView commitAnimations];
// [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:#selector(doneAnimation) userInfo:nil repeats:NO];
[masterViewController release];
[detailViewController release];
This is how we have to add splitview controler you have to check the condition weather you are logged in or not and then call this in a method
#interface ViewController : UIViewController { //....yor variables }
in ViewController.m file:
(void)viewDidLoad {
[super viewDidLoad];
self.title = #"Sample Email Application"; // title of navigation bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:#selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }
-(void) composeMail: (id) sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTintColor:[UIColor blackColor]];
[picker setSubject:#"Sample Email Application"];
[picker setMessageBody:[NSString stringWithFormat:#"Visit for more help %#. ",#"http://google.com"] isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[controller dismissModalViewControllerAnimated:YES];
}
It looks like you are missing the -setToRecipients, which you can't send mail unless you have an address to send to.
[picker setToRecipients:[NSArray arrayWithObjects:#"your#emailstring.com", nil]];
I'm working on an iPhone/iPad application and trying to switch views through a function call, not by a button. I've seen lots of sources switching views triggered by a button, but there's nothing that explains how to switch views triggered by a function. I tried to do this on my own, but it failed. Here's the code that I tried:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.webview == nil) {
self.webview = [[MainViewController alloc] init];
/* webview initialized with storyboard */
if (self.view.superview == nil) {
[self.view insertSubview:self.webview.view atIndex:0];
}
[storyboard release];
}
}
This is viewDidLoad of the viewController.m. First, it shows WebView.
- (void)changeView {
self.normview = [[AlternateViewController alloc] init];
/* normview initialized with storyboard */
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.webview viewWillDisappear:YES];
[self.webview viewDidDisappear:YES];
[self.webview.view removeFromSuperview];
[self.view insertSubview:self.normview.view atIndex:0];
[self.normview viewWillAppear:YES];
[self.normview viewDidAppear:YES];
[UIView commitAnimations];
}
And when this changeView function (in a viewController.m) is called, It should change the view from webview to normview (actually, it works fine when the same code is triggered by a button). But when I call this function in other file (not viewController.m), such as
ViewController *viewcontroller = [[ViewController alloc] init];
[viewcontroller changeView];
It doesn't work. Anyone can give a clue to solve this or an alternative way? (ps. I'm testing on iPad.)
You can switch views with this function:
YourView *screen = [[YourView alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:screen animated:YES];
[screen release];
You can set the modaltransitionstyle to your willings.
Don't forget to import your headerfile at the top of your class.
#import "YourView.h"
I am new to iphone development.I have created a tabbar based application . In the first i want the email composer to be displayed. I am able to display it but the cancel and send button are not working,I don't know where do i go wrong .Please help me out. Here is my code.
- (void)viewDidLoad
{
[super viewDidLoad];
[self displayComposerSheet];
}
-(void)displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
[[picker navigationBar] setTintColor:[UIColor blackColor]];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail])
{
[picker setToRecipients:[NSArray arrayWithObjects:#"name#gmail.com",nil]];
[picker setSubject:#"Sample"];
}
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You are presenting the mail composer twice.
Remove the line:
[self.view addSubview:picker.view];
And replace the next line with:
[self.navigationController presentModalViewController:picker animated:YES];
If you are adding only subview of mailcomposser you have to remove it from self.view,
In your code you are adding subview and present also,
If you are use only use [self.view addSubview:picker.view]; than
Try with to remove it.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[controller.view removeFromSuperview];
}
I'm still suggest to use
[self.navigationController presentModalViewController:picker animated:YES]; for Present MFMailComposeViewController ,
and use [self dismissModalViewControllerAnimated:YES]; to dismiss it.
Use this code:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObjects:#"niftyapplications#gmail.com", #"support#niftysol.com", nil];
[controller setToRecipients:toRecipients];
[controller setTitle:#"Contact Us"];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self becomeFirstResponder];
NSString *strMailResult;
switch (result)
{
case MFMailComposeResultCancelled:
strMailResult = NSLocalizedString(#"E-Mail Cancelled",#"");
break;
case MFMailComposeResultSaved:
strMailResult = NSLocalizedString(#"E-Mail Saved",#"");
break;
case MFMailComposeResultSent:
strMailResult = NSLocalizedString(#"E-Mail Sent",#"");
break;
case MFMailComposeResultFailed:
strMailResult = NSLocalizedString(#"E-Mail Failed",#"");
break;
default:
strMailResult = NSLocalizedString(#"E-Mail Not Sent",#"");
break;
}
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"ISO Audit",#"") message:strMailResult delegate:self cancelButtonTitle:NSLocalizedString(#"OK",#"") otherButtonTitles:nil];
[alertView show];
[self dismissModalViewControllerAnimated:YES];
}
Set Delegate of MFMailComposeViewController
MFMailComposeViewController *mailcomposer = [[MFMailComposeViewController alloc]init];
mailcomposer.mailComposeDelegate = self;
And Use this Delegate Method
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
}