在我的应用中包含电子邮件应用的问题

时间:2011-01-14 07:19:03

标签: iphone sendmail modalviewcontroller

按下按钮时,会显示MFMailComposeViewController

到目前为止我已经完成了。

我的问题是:

  1. 是否可以在按下取消按钮时禁用弹出操作页?
  2. 是否可以将 主题字段设为不可编辑?
  3. 我想将左栏按钮更改为返回
  4. 我该怎么做?

    - (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];
    }
    

2 个答案:

答案 0 :(得分:3)

是的,所有三种都是可能的,但是#2要么需要使用私有API,要么使用一些hackery。 我采用了子类化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] init]; to [[CustomMailComposeViewController alloc] init];

答案 1 :(得分:0)

快速回答!

  1. 没有
  2. 没有
  3. 没有
  4. 抱歉