Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Scouze

macrumors newbie
Original poster
Mar 3, 2010
7
0
Hi,

I'm trying to add an 'email the text in the view below' type of button to my iphone application. I've followed the code examples in the Sam's 'Learn In 24 Hours' book and looked at similar code on the net. So far all that happens is the email view animates up but none of the fields can be edited so the user can't enter a 'To' field. Tapping on the screen doesn't make the keyboard appear. The 'Cancel' button works but not the 'Send' so even if I add 'To' recipients programmatically it still won't go anywhere.

My guess is that it's a keyboard-delegate kind of problem but after looking through doc's there doesn't seem to be any specific instructions on making sure the keyboard is 'attached' to the email composition view. BTW: it's a standard flipSideView template as created in Xcode's New Project. The flipSideView contains two toolbars with 3 buttons for dismissing the view, email the summary text and clearing the summary text. The text is displayed in a UITextView.

In my .h file I've got:


Code:
#import <UIKit/UIKit.h>
#import "GlobalVariablesEngine.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
@protocol FlipsideViewControllerDelegate;
@class MainViewController;

@interface FlipsideViewController : UIViewController <MFMailComposeViewControllerDelegate,UINavigationControllerDelegate>

{	
	id <FlipsideViewControllerDelegate> delegate;
	IBOutlet UITextView *summaryContainer;
	NSMutableString *flipSideSummary;
	IBOutlet UIBarButtonItem *emailButton;
}

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, retain) NSMutableString *flipSideSummary;
- (IBAction)done;
- (IBAction)clearSummary:sender;
- (IBAction)emailSummary:sender;
@end


@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
And in the .m file there's:

Code:
#import "FlipsideViewController.h"

@implementation FlipsideViewController

@synthesize delegate;
@synthesize flipSideSummary;

- (void)viewDidLoad {
    [super viewDidLoad];
    
	if (![MFMailComposeViewController canSendMail]) {
		[emailButton setEnabled:FALSE];
	}
	self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
	[summaryContainer setFont:[UIFont fontWithName:@"Courier" size:13.0]];
	GlobalVariablesEngine *globalVariables = [GlobalVariablesEngine sharedInstance];
	[summaryContainer setText:[globalVariables getSummary]];
}


- (IBAction)done {
	[self.delegate flipsideViewControllerDidFinish:self];	
}

- (IBAction)clearSummary:sender
{
	GlobalVariablesEngine *globalVariables = [GlobalVariablesEngine sharedInstance];
	[globalVariables resetSummary];
	[summaryContainer setText:[globalVariables getSummary]];
}

- (IBAction)emailSummary:sender
{
	GlobalVariablesEngine *globalVariables = [GlobalVariablesEngine sharedInstance];
	MFMailComposeViewController *summaryMessage = [[MFMailComposeViewController alloc]init];
	summaryMessage.mailComposeDelegate = self;
	[summaryMessage setToRecipients:nil];
	[summaryMessage setSubject:@"Summary from iPhone."];
	[summaryMessage setMessageBody:[globalVariables getSummary] isHTML:NO];
	[self presentModalViewController:summaryMessage animated:YES];
	[summaryMessage release];
}

#pragma mark -
#pragma mark MFMailComposeViewControllerDelegate

-(void)mailComposeController:(MFMailComposeViewController *)summaryMessage didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
	[summaryMessage dismissModalViewControllerAnimated:YES];
}

- (void)dealloc {
    [super dealloc];
}

@end
As I say, the email compose view animates nicely up but can't be edited at all. Would someone like to point out the blindingly obvious step I've missed!

Thanks!

Todd

 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.