2012-04-11 77 views
0

我正在使用dataDetectorTypes屬性與UITextView.code工作正常。當點擊電子郵件地址時設置默認主題

當我點擊鏈接的電子郵件作曲家出現帶有預填充:[電子郵件地址],但我想設置默認主題:[主題字符串]也。

我該怎麼做?

+0

你是如何解決這個問題的? – 2014-01-30 11:50:06

回答

1
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 

    mailController.mailComposeDelegate = self; 

if([MFMailComposeViewController canSendMail]){ 
    [mailController setSubject:@"Subject"]; 
    [mailController setMessageBody:@"Email body here" isHTML:NO]; 
    [mailController setMessageBody:[self getInFo] isHTML:YES]; 
    [mailController setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; 
    [mailController setTitle:@"Title"]; 

    [self presentModalViewController:mailController animated:YES]; 
}else{ 
    [mailController release]; 
} 
+0

這不是我要找的。當我嘗試通過單擊uitextview中的電子郵件發送郵件並將dataDetectorTypes屬性設置爲UIDataDetectorTypeAll時,我想添加主題。 – 2012-04-11 11:33:13

2

1)拳頭將<UITextViewDelegate, MFMailComposeViewControllerDelegate>添加到包含textview的類中。

您必須添加兩個進口該類:

#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMailComposeViewController.h> 

2)添加一個變量:MFMailComposeViewController(在這個例子中mailVC,你也可以將其添加爲您的.h類屬性)

3)實施下一個方法:

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange 

這允許截取特定的url交互。您可以取消特定的相互作用,並添加自己的行動,例如:

-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{ 
    //EXAMPLE CODE 
    if ([[URL scheme] isEqualToString:@"mailto"]) { 

     mailVC = [[MFMailComposeViewController alloc] init]; 
     [mailVC setToRecipients:@[@"[email protected]"]]; 
     [mailVC setSubject:@"A subject"]; 
     mailVC.mailComposeDelegate = self; 

     [self presentViewController:mailVC animated:YES completion:^{ 
      // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 
     }]; 
     return NO; 
    } 
    return YES; 
} 

3)要關閉MFMailComposeViewController變量:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 
    [mailVC dismissViewControllerAnimated:YES completion:nil]; 
} 

這對我的作品!

相關問題