2011-04-22 4 views
0

나는 UITable을 가지고 있는데, "Mail"이라는 셀을 클릭하면 sendMailViewController를 push하려고한다. 이 sendMailViewController에서 메일 작성보기를 추가하는 방법?

,있는 viewDidLoad에서 나는 부를 것이다 [자기 displayComposerSheet] :

이 이론적으로 이것에 대해 갈 수있는 올바른 방법이 될 것인가?

-(void)displayComposerSheet 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Hello from California!"]; 

    // Set up recipients 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 

    // Attach an image to the email 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"]; 

    // Fill out the email body text 
    NSString *emailBody = @"It is raining in sunny California!"; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 

답변

0

는 indexpath.row

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
if(indexPath.row==*give your row no*) 
{ 

if([MFMailComposeViewController canSendMail]){ 

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Hello from California!"]; 

    // Set up recipients 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 

    // Attach an image to the email 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"]; 

    // Fill out the email body text 
    NSString *emailBody = @"It is raining in sunny California!"; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 

     } 
     else 
     { 
      //NSLog(@"Message cannot be sent"); 
     } 
} 


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


} 
0

올바른 보이지만 예방 조치로 당신은 추가해야합니다 :

if ([MFMailComposeViewController canSendMail]) 
{ 
    ....your picker code... 
} 
else { 
    // alert user that they can't send email? 
} 
+0

위해 무엇을 좋아, 감사, 그래서 IB에서 설정에 아무것도 오른쪽? 그 외의 경우에는'[self launchMailAppOnDevice];를 추가하십시오. 감사. –

+0

사실, 다른 sendMailViewController를 만들 필요가 없습니다. 당신이 가지고있는 것이면 괜찮지 만 - (void) tableView : (UITableView *) 내에서 'displayComposerSheet'를 호출 할 수 있습니다. tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath {} MFMailComposeViewController가 현재보기 위에 표시되어야합니다. – dredful

0

귀하의 코드가 잘 보이지만, 오히려 새로운 뷰 컨트롤러를 밀어보다, 당신의 UITableViewController에서 당신이 MFMailComposeViewController을 제시 권하고 싶습니다 및 그것을 거기에서 선물한다 - 그것은 아마 이상하고 불필요하게 보일 것이다. 당신의 didselectRow에서

관련 문제