PDA

View Full Version : UILabel text in email body




nickculbertson
Jan 28, 2011, 02:08 PM
In the following code:


- (IBAction)email:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"message"
delegate:self
cancelButtonTitle:@"Thanks! Maybe Later"
otherButtonTitles:@"Email Name", @"Review",nil];

[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 2){
//
}if (buttonIndex == 1){
MFMailComposeViewController *picker =
[[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Name"];


NSString *emailBody = @"Hello my name is _______ _______ . What is yours?";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];

}if (buttonIndex == 0){
//
}
}

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


is it possible to add the text from 2 UILabels into the blanks here:


NSString *emailBody = @"Hello my name is _______ _______ . What is yours?";

?

Thanks,
Nick



dejo
Jan 28, 2011, 02:54 PM
is it possible to add the text from 2 UILabels into the blanks here:


NSString *emailBody = @"Hello my name is _______ _______ . What is yours?";

?

Yes. NSString's stringWithFormat: is perfectly suited to this need. Make sure you check out the String Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/introStrings.html) for more information.

nickculbertson
Jan 29, 2011, 09:32 AM
Yes. NSString's stringWithFormat: is perfectly suited to this need. Make sure you check out the String Programming Guide (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/introStrings.html) for more information.

Thank you, again. I'll read over the documentation this weekend.

nickculbertson
Feb 3, 2011, 11:12 AM
Alright, I got it to work with stringWithFormat:

NSString *emailBody = [NSString stringWithFormat:@"Hello, %@ %@ %@ %@ . Goodbye", textview.text, textview2.text, textview3.text, textview4.text];

Is there a way to have the resulting text appear on multiple lines?


Hello,
My Name Is .
Goodbye

Thanks,
Nick

dejo
Feb 3, 2011, 12:14 PM
Is there a way to have the resulting text appear on multiple lines?
Yeah, just use \n (the newline specifier) in your format string.

nickculbertson
Feb 3, 2011, 12:59 PM
Yeah, just use \n (the newline specifier) in your format string.

Thanks, you are correct. I had tried using \n but I couldn't get it to work. As it turns out I coded the line break the right way but it just didn't translate properly in the email body. I ran

NSLog([NSString stringWithFormat:@"Hello, \n %@ %@ %@ %@ . \n Goodbye.", textview.text, textview2.text, textview3.text, textview4.text]);

it starts a new line at \n. however in

NSString *emailBody = [NSString stringWithFormat:@"Hello, \n %@ %@ %@ %@ . \n Goodbye.", textview.text, textview2.text, textview3.text, textview4.text];

the email text appears on one line.

Oh well, it isn't totally necessary for my project. I just thought I'd add some ascii art.

EDIT:

Ah ha! this line was in the way.

[picker setMessageBody:emailBody isHTML:YES];

changed it to

[picker setMessageBody:emailBody isHTML:NO];

Thanks,
Nick

dejo
Feb 3, 2011, 01:19 PM
Ah ha! this line was in the way.

[picker setMessageBody:emailBody isHTML:YES];

changed it to

[picker setMessageBody:emailBody isHTML:NO];

Thanks,
Nick
Well, if you want HTML, you can just use <br> instead of \n.