I'm trying to set it up so people can email from within my application. I'm referencing this post to do this, but I'm getting these warnings on the build:
and then when I run it, it bugs:
I'm wondering if I've simply placed the code in the wrong area. Just so you know I have placed
#import <MessageUI/MessageUI.h>
in the header file.
Thanks for the help!
EDIT 1
It seems as if the problem lies within how my ViewController is setup. In fact all my UI code is in a separate object as shown below. This is making it difficult for me to understand which code goes where. Any advice?
Add the MessageUI framework into your framework folder and
import these classes in your viewController.h:-
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface *your controller* : UIViewController <MFMailComposeViewControllerDelegate>
Well it looks like your SpeakHereController isn't a UIViewController.
Therefore it can't find the methods for presenting and dismissing the modalViewController.
Also you need to implement the MFMailComposeViewControllerDelegate, add it to your viewcontroller.
Here is the code
#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface tempsend : UIViewController<MFMailComposeViewControllerDelegate>
//.m file code
MFMailComposeViewController *picmail = [[MFMailComposeViewController alloc] init];
picmail.mailComposeDelegate = self;
[picmail setSubject:#"Exporting DDT file"];
// Set up recipients
[picmail setToRecipients:[NSArray arrayWithArray:aray_emailid]];
[picmail setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picmail animated:YES];
[picmail release];
Regards,
Shyam
Add MFMailComposeViewControllerDelegae to SpeakHereController.h file
And use
[controlle presentModalViewController:controller animated:YES];
Instead of
[self presentModalViewController:controller animated:YES];
Same for
[controlle dismissModalViewControllerAnimated:YES];
Instead of
[self dismissModalViewControllerAnimated:YES];
Related
im designing a app thats a single view application and i am adding the code so that i can switch views via a button but every-time i enter my code that was working in IOS 5 it now comes up with a error ? heres the code
#import <UIKit/UIKit.h>
#interface ViewController1 : UIViewController
- (IBAction)home:(id)sender;
#end
#import "ViewController1.h"
#import "ViewController.h"
#interface ViewController1 ()
#end
#implementation ViewController1
- (IBAction)home:(id)sender
{
ViewController *second =[[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
heres the error
thank you!!
edited answers my errors now ??
by the way i really appreciate it and i will give you good tick by your answer once done this is the errors now??
First of all, this is not an error but it is warning.
And for help you can read the documents provided by Apple.
And to remove that warning just use the below code
[self presentViewController:second animated:YES completion:^{ }];
(I've just learn objective-c for a short time. I still don't know how to generate UI elements through writting code now.)
There is one button in .xib.
There is one method in .m.
I want to link these two things by ctrl-click "Touch up Inside" and "File's owner". However, no method shows up when I move the mouse cursor onto File's Owner's icon.
The situation is like this:
http://www.badongo.com/pic/13577347
the .h file:
#import <UIKit/UIKit.h>
#interface ChangeViewController : UIViewController
{
}
-(IBAction)goToSecondView:(id)sender;
-(IBAction)goToCalculatorView:(id)sender;
-(IBAction)test:(id)sender;
#end
the .m file:
#import "ChangeViewController.h"
#import "SecondViewController.h"
#import "CalculatorViewController.h"
#implementation ChangeViewController
-(IBAction)goToSecondView:(id)sender
{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
}
-(IBAction)goToCalculatorView:(id)sender
{
CalculatorViewController *calculatorViewController =[[CalculatorViewController alloc] initWithNibName:#"CalculatorViewController" bundle:nil];
[self.navigationController pushViewController:calculatorViewController animated:YES];
[calculatorViewController release];
}
Is there anything wrong? Thanks.
Also make sure your File's Owner class is of type 'ChangeViewController'. For doing so, select the File's Owner, Go to the inspector (press command + 4), and set its class to 'ChangeViewController' if not already set.
Please confirm the below points:
1) Have you defined method in .h file?
2) Have you defined method with -(IBAction)
Hope you will be able to bind it.
Cheers.
Double click on file owner's than you will see list of methods you have defined. Connect than method to you control by drag and drop. Once you will attach that method to your button, all the events that can be fired will be displayed. Select TouchUpInside...
link
I'm having an issue with the dismissModalViewControllerAnimated method.
The header looks like this:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "GADBannerView.h"
#import "weatherSetUp.h"
#interface weatherPicViewController : UIViewController{
In my viewController.m file I call
-(IBAction)didClickSetting:(id)sender{
weatherSetUp *views = [[weatherSetUp alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:views animated:YES];
}
This all works fine, In my weatherSetUp file once the user has completed set up I was to dismiss the modal view. I do it by calling this method in the above viewController.m file:
-(void)dismissModal{
[self.parentViewController dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];
[self dismissModalViewControllerAnimated:NO];
[self.parentViewController dismissModalViewControllerAnimated:NO];
NSLog(#"Model gone!");
}
But none of these work.
This is the header file of my weatherSetUp file:
#import <UIKit/UIKit.h>
#import "viewController.h"
#interface weatherSetUp : UIViewController
-(IBAction)didClickClose:(id)sender;
#end
And the only method I've implemented is:
-(IBAction)didClickClose:(id)sender{
NSLog(#"CLick ");
viewController *viewEr = [[viewController alloc] init];
[viewEr dismissModal];
}
All the NSLog's work when I click the button, I've searched on here and tried too the above ways of dismissing it and none of them work, any ideas?
What is going wrong is you're calling dismissModal on a random view controller rather than the object that actually has the modal controller. What you'd want to do in didClickClose: is this
[[self parentViewController] dismissModalViewControllerAnimated:NO];
Also, you shouldn't be starting your class names with lowercase characters in Cocoa. They should really be capitalised and have a prefix, eg ABCWeatherSetUp. The prefix can be whatever you want, but generally you want something based on your name, your company's name or your project's name.
insted of [self.parentViewController dismissModalViewControllerAnimated:NO];
write this [self dismissModalViewControllerAnimated:NO];
Your viewEr is not the same viewController which you are trying to close, because you are creating the new object of your viewContoller.
you can create a viewContoller properties and in your viewController class file
weatherSetup.viewController = self.parentViewController;
NOTE: do not use viewContoller as a ivar, use different may name.
I've been trying to switch two views from two separate view controllers for a while and it never works, the simulator always crashes to the home screen. I'm using Xcode 3.2.5 and this is my code -
SwitchViewsViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
#interface SwitchViewsViewController : UIViewController {
}
-(IBAction)pushButton;
#end
SwitchViewsViewController.m
#import "SwitchViewsViewController.h"
#import "SecondViewController.h"
#implementation SwitchViewsViewController
-(IBAction)pushButton {
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES]
[screen release];
}
SecondViewController.h
#import <UIKit/UIKit.h>
#interface SecondViewController : UIViewController {
}
-(IBAction)pushBack;
#end
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
-(IBAction)pushBack{
[self dismissModalViewControllerAnimated:YES];
}
In interface builder, all i've done is linked the file's owner classes and the buttons. Also made the SwitchViewsViewController load first, and not MainWindow. Everything builds but when I try to run the app it crashes and sends it to the home screen. Can anyone help me with this?
When you alloc your secondViewController you init with nib name nil, this should actually be the name of your nib file.
SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
Also, you should close your brackets ;-)
XIB errors are rarely uncovered at compile time. So when you say you made SwitchViewsViewController the starting point of the app, I am assuming that you have altered the main nib file in Info.plist. Usually that nib file is responsible for providing information about the application delegate. So it's a pretty bad idea if you've changed it to SwitchViewsViewController. I suggest you incorporate the MainWindow.xib back. This is easier I think but if you are interested in doing programmatically than take a look at this post.
I'm halfway through implementing a very basic 'Add Contact' Button. I am calling the 'Add View' using the code (via a linked UIButton, that works) :
- (IBAction)showAddContact {
NSLog(#"Hit showAddContact");
ABNewPersonViewController *newPersonViewController = [[ABNewPersonViewController alloc] init];
addContactNavController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
[self presentModalViewController:addContactNavController animated:YES];
}
and then I have also set the delegate resonse of:
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person {
NSLog(#"Hit newPersonViewController");
//ABContact *contact = [ABContact contactWithRecord:person];
[self.navigationController popViewControllerAnimated:YES];
}
in my header I have set:
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#interface test2ViewController : UIViewController <ABNewPersonViewControllerDelegate> {
UINavigationController* addContactNavController;
}
- (IBAction)showAddContact;
#end
I have added the frameworks Addressbook and AddressBookUI.
The add dialog box comes up as expected, I can edit the contact, but I am not able to remove the modal View Controller from the view.
I have even duplicated the problem in a simple test project available here:link text
What am I missing?, I bet it is something extremely simple.
Thanks #norskben
Couple of problems:
You should release the ABNewPersonViewController after presenting it.
You present the ABNewPersonViewController as a modal dialog with presentModalViewController: but you remove it from the screen as if it was pushed on a UINavigationController with popViewControllerAnimated:. Instead you should either push and pop, or present and dismiss. (If you don't know what this means, read a little int he View Controller documentation)
Even though you implement the ABNewPersonViewControllerDelegate protocol, you never set the delegate property of the ABNewPersonViewController.