2011-01-14 53 views
3

按下按鈕時,顯示MFMailComposeViewController在我的應用程序中包含電子郵件應用程序的問題

到目前爲止我已經完成了。

我的問題是:

  1. 是否有可能禁用動作片按下取消按鈕時,彈出?
  2. 是否有可能使主題字段不可編輯?
  3. 我想將左欄按鈕更改爲返回

我該怎麼做?

- (IBAction)questionButtonPressed:(id)sender { 
    email = [[MFMailComposeViewController alloc] init]; 
    email.mailComposeDelegate = self; 

    // Subject 
    [email setSubject:@"Testing"]; 

    // Optional Attachments 
    NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:@"albumart.png"]); 
    [email addAttachmentData:artwork mimeType:@"image/png" fileName:@"albumart.png"]; 

    // Body 
    //[email setMessageBody:@"This is the body"]; 

    // Present it 
    [self presentModalViewController:email animated:YES]; 
} 

回答

3

是三者都是可能的,但是#2要麼需要使用私有API或一些兩輪牛車。 我把子類MFMailComposeViewController的方法如下

// file: CustomMailComposeViewController.h 
@interface CustomMailComposeViewController : MFMailComposeViewController { 

} 
@end 

// file ustomMailComposeViewController.m 
#import "CustomMailComposeViewController.h" 
@implementation CustomMailComposeViewController 

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    //Here we replace the cancel button with a back button (Question #3) 
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; 
    self.navigationBar.topItem.leftBarButtonItem = backButton; 
    [backButton release]; 


    //Here we disallow the user to change to to: cc: bcc: and subject: feilds (Question #2) 
    //Warning: the xxxField methods are undocumented private methods. 
    UITableViewController *vc = [self.viewControllers objectAtIndex:0]; 
    UITableView *tvv = [vc view]; 
    [[tvv toField] setUserInteractionEnabled:NO]; 
    [[tvv ccField] setUserInteractionEnabled:NO]; 
    [[tvv bccField] setUserInteractionEnabled:NO]; 
    [[tvv multiField] setUserInteractionEnabled:NO]; 
    [[tvv subjectField] setUserInteractionEnabled:NO]; 
} 


//This is the target for the back button, to immeditally dismiss the VC without an action sheet (#1) 
-(void) backButtonPressed:(id)sender { 
    [self dismissModalViewControllerAnimated:YES]; 
} 
@end 

要在代碼中使用你會改變:[MFMailComposeViewController的alloc]初始化]到[[CustomMailComposeViewController alloc] init];

0

快速回答!

  1. 沒有
  2. 沒有
  3. 沒有

對不起

+0

我不同意:1:是的,2:是的,但不建議App Store(私人api),3:是的 – 2011-01-14 09:28:05

+0

檢查答覆發佈者@Brad – xydev 2011-01-14 13:01:10

相關問題