2011-09-10 7 views
0

私はplistを使用してuitableviewにデータを入力しています。私の鍵の1つが電子メールなので、どのタイプになるのだろうかと疑問に思っていましたか?データ、文字列など基本的なアイデアは、テーブルを持って、あなたは電子メールセルをタップし、電子メールモーダルビューが付属しています。これをどうやってやるの?私が使用する おかげplistにデータを書き込むとき、電子メールはどのようなタイプになりますか?

答えて

0

データ型は文字列になります。この文字列を引き出して、必要な場所で使用することができます。

#pragma mark - 
#pragma mark Compose Mail 

-(void)callMailComposer 
{ 
    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]; 
     } 
     else 
     { 
      [self launchMailAppOnDevice]; 
     } 
    } 
    else 
    { 
     [self launchMailAppOnDevice]; 
    } 
} 

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayComposerSheet 
{ 
    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]; 
    picker=nil; 
} 

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

    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. 
-(void)launchMailAppOnDevice 
{ 

//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]]; 
} 
+0

変更次の2行の「if(ピッカー:Eメールの場合は、あなたが次のことを行う必要があります(私はあなたがPLISTの外に列を読み、UITableViewCellの中にそれを使用することができますと仮定しています) )[picker release]; if(picker)picker = nil; " 〜[ピッカーリリース]; " –

関連する問題