-2

i know how to add in app email, but i dont know how to email the text of my table view. I do, but my problem is that when the user adds a cell to the table, how do i get that to print out too? to print out the text normally i would use

string = [[NSString alloc]initWithFormat:@"%@ \n %@ \n %@",[array objectAtIndex:0], 
                                                           [array objectAtIndex:1], 
                                                           [array objectAtIndex:2]];

and i set the email Body to string. Does anyone know how to make it to where if a new cell is added, i can get it to be added to the email body as well??

Thanks

kurt moyer
  • 31
  • 1
  • 8

3 Answers3

2

I'm not 100% sure I understand your problem but here goes . . .

You can make your code deal with more than a fixed number of items like this :

string = [array componentsJoinedByString:@" \n "];

If array is also the data source for your table view then string should then contain all the table cells with a break between them.


You can only update the body of your email in an MFMailComposeViewController before you have shown the email view to the user - once it's been displayed then it's read only :(

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • ok this works perfect!! but i have a plist that populates the table and i stored the contents of the plist into an array called "cells" so i said: string = [cells components...]; and it prints out some extra stuff like keys in my plist? do you know how to fix this? – kurt moyer Jul 15 '11 at 17:11
0

I assume here that your array is populated with string objects.

Compose the string:

NSString *theMessage = [NSString stringWithFormat:@"%@ \n %@ \n %@,", [array objectAtIndex:0], [array objectAtIndex:1], [array objectAtIndex:2]];

Now, assuming you also have an instance of MailViewController, instantiated as mailViewController, write this code in for the body:

[mailViewController setMessageBody:theMessage isHTML:NO];
ArtSabintsev
  • 5,170
  • 10
  • 41
  • 71
  • 1
    Thought I'm not sure I understand your problem. – ArtSabintsev Jul 15 '11 at 16:45
  • yes this is what i had but my users can add cells and i wanted that text to be printed out too and it works with string = [cells components...]; thanks a lot though! :D – kurt moyer Jul 15 '11 at 16:53
  • No problem - glad you got it working in a different way. Mind dropping some sample code in here - I may need to implement something similar very soon. – ArtSabintsev Jul 15 '11 at 17:01
  • Yeah well good luck! if u need any help with implementing the email view then let me know i have the code all written out! :D – kurt moyer Jul 15 '11 at 17:03
0

First populate the UItableView formatting the strings with the methods indicated over, then in your:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath:

UITableViewCell *cellView = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];//Section 0  
NSString *string=cellView.textLabel.text;
//compose email body with string

Hope this helps.

Mat
  • 7,613
  • 4
  • 40
  • 56