Take the 2-minute tour ×

I'm in the process of using a plist to populate a uitableview. I was wondering, because one of my keys is email, what type would it be? Data, string, etc. The basic idea is to have a table, you tap the email cell, and up comes with the email modal view. How do i go about doing this? Thanks

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The data type I would use would be a string. You can then pull out this string and use it where you need it. In the case of email, you will need to do the following (I am assuming you are able to read the string out of the plist and use it within a UITableViewCell):

#pragma mark -
#pragma mark Compose Mail

    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
        // We must always check whether the current device is configured for sending emails
        if ([mailClass canSendMail])
            [self displayComposerSheet];
            [self launchMailAppOnDevice];
        [self launchMailAppOnDevice];

// Displays an email composition interface inside the application. Populates all the Mail fields. 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"My email subject"];

   //Just an extra example if you were wanting to add an attachment :)
   /* NSString* pdfFileName = @"pdf_file.pdf";
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:pdfFileName];

    [picker addAttachmentData:[NSData dataWithContentsOfFile:documentDirectoryFilename] mimeType:@"application/pdf" fileName:pdfFileName]; */

    // Set up recipients
    [picker setCcRecipients:nil];   
    [picker setBccRecipients:nil];
    [picker setToRecipients:[NSArray arrayWithObjects:@"myEmailAddressFromPlist",nil]];

    NSString *emailBody = @"Hey you got mail";
    [picker setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:picker animated:YES];

    [picker release];

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
    NSString* alertMessage;
    // Notifies users about errors associated with the interface
    switch (result)
        case MFMailComposeResultCancelled:
            alertMessage = @"Email composition cancelled";
        case MFMailComposeResultSaved:
            alertMessage = @"Your e-mail has been saved successfully";
        case MFMailComposeResultSent:
            alertMessage = @"Your email has been sent successfully";
        case MFMailComposeResultFailed:
            alertMessage = @"Failed to send email";
            alertMessage = @"Email Not Sent";

    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"My application" message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];

    [self dismissModalViewControllerAnimated:YES];

#pragma mark Workaround

// Launches the Mail application on the device.

//You will need to fill these in 
    NSString *recipients = @"mailto:?cc=&subject=";
    NSString *body = @"&body=";
    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
share|improve this answer
Change these two lines "if(picker) [picker release]; if(picker) picker=nil;" to "[picker release];". –  Johan Kool Sep 11 '11 at 5:21

Your Answer


