2013-12-14 59 views
0

我有一個TableView設置爲在用戶選擇列表中的某個項目時觸發不同的ViewController,但我希望「聯繫我們」觸發消息框架(在應用程序電子郵件中),以便用戶可以發送電子郵件,不會被推送到ViewController。在ViewController中發送來自TableView的電子郵件

有什麼建議嗎?以下是我用於「聯繫我們」的一段代碼。

對不起,如果這是一個明顯的答案,隨着我的學習,羨慕你所有的嚮導!

NSMutableDictionary *sectionContactUs = [NSMutableDictionary dictionary]; 
    [sectionContactUs setObject:kSlideViewControllerSectionTitleNoTitle forKey:kSlideViewControllerSectionTitleKey]; 
    [sectionContactUs setObject:@"Contact Us" forKey:kSlideViewControllerSectionTitleKey]; 
    NSMutableDictionary *contactUsViewControllerDictionary = [NSMutableDictionary dictionary]; 
    [contactUsViewControllerDictionary setObject:@"Contact Us" forKey:kSlideViewControllerViewControllerTitleKey]; 
    [contactUsViewControllerDictionary setObject:@"ContactUsViewController" forKey:kSlideViewControllerViewControllerNibNameKey]; 
    [contactUsViewControllerDictionary setObject:[ContactUsViewController class] forKey:kSlideViewControllerViewControllerClassKey]; 
    [sectionTest setObject:[NSArray arrayWithObject:contactUsViewControllerDictionary] forKey:kSlideViewControllerSectionViewControllersKey]; 
    [datasource addObject:sectionContactUs]; 

回答

0

使用MFMailComposeComposeView: 首次進口MessageUI框架項目 譜寫您的視圖控制器#import <MessageUI/MessageUI.h>也在接口添加MFMailComposeViewControllerDelegate

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; 
controller.mailComposeDelegate = self; 
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
[controller setToRecipients:toRecipients]; 
[controller setTitle:@"Contact Us"]; 
[controller setSubject:@"Your Mail Subject"]; 
[controller setMessageBody:@"Mail body here \n Comments" isHTML:NO]; 

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) 
{ 
    controller.modalPresentationStyle = UIModalPresentationFormSheet; 
} 
else 
{ 
    controller.modalPresentationStyle = UIModalPresentationFullScreen; 
} 
[self presentModalViewController:controller animated:YES]; 

另請參見此方法小號

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
    [self becomeFirstResponder]; 
    NSString *strMailResult; 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      strMailResult = NSLocalizedString(@"E-Mail Cancelled",@""); 
      break; 
     case MFMailComposeResultSaved: 
      strMailResult = NSLocalizedString(@"E-Mail Saved",@""); 
      break; 
     case MFMailComposeResultSent: 
      strMailResult = NSLocalizedString(@"E-Mail Sent",@""); 
      break; 
     case MFMailComposeResultFailed: 
      strMailResult = NSLocalizedString(@"E-Mail Failed",@""); 
      break; 
     default: 
      strMailResult = NSLocalizedString(@"E-Mail Not Sent",@""); 
      break; 
    } 

    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Message",@"") message:strMailResult delegate:self cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil]; 
    [alertView show]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+1

正是我需要的,完美的工作!謝謝你,先生。 – Sean

0

可以打開MFMailComposeViewController用於發送郵件..

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


    [picker setMessageBody:@"Body message" isHTML:NO]; 
    [self presentModalViewController:picker animated:YES]; 
    } 
} 


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
[self dismissModalViewControllerAnimated:YES]; 
//////nslog (@"mail finished"); 
} 
+0

確保將委託添加到.h文件:MFMailComposeViewControllerDelegate – Milo