2010-03-27 46 views
5

我是iphone開發新手。我創建了一個基於tabbar的應用程序。在第一個我想要顯示電子郵件作曲家。我能夠顯示它,但取消和發送按鈕不起作用,我不知道我哪裏出錯。請幫助我。這是我的代碼。不能解僱iPhone中的電子郵件作曲者視圖?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self displayComposerSheet];  
} 

-(void)displayComposerSheet 
{ 
    picker = [[MFMailComposeViewController alloc] init]; 

    [[picker navigationBar] setTintColor:[UIColor blackColor]]; 

    picker.mailComposeDelegate = self; 

    if ([MFMailComposeViewController canSendMail]) 
    { 

      [picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]]; 

      [picker setSubject:@"Sample"]; 

    } 
    [self.view addSubview:picker.view]; 
    [self presentModalViewController:picker animated:YES]; 

} 

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 

    [self dismissModalViewControllerAnimated:YES]; 

} 

回答

1

您正在展示郵件編輯器兩次。

刪除行:

[self.view addSubview:picker.view]; 

,取而代之的下一行:

[self.navigationController presentModalViewController:picker animated:YES]; 
+0

對不起,現在我無法看到郵件編輯器視圖本身。 – Warrior

+0

我想在郵件編輯器視圖中顯示標籤欄 – Warrior

0

集代表MFMailComposeViewController

MFMailComposeViewController *mailcomposer = [[MFMailComposeViewController alloc]init]; 

mailcomposer.mailComposeDelegate = self; 

,並使用該委託的方法

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
} 
0

使用此代碼:

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.modalPresentationStyle = UIModalPresentationFormSheet; 
[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(@"ISO Audit",@"") message:strMailResult delegate:self cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil]; 
    [alertView show]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 
3

如果你不得不從self.view, 刪除它在你的代碼被添加子視圖和現在也正在添加mailcomposser的唯一子視圖,

如果您只能使用[self.view addSubview:picker.view];而不是 請嘗試將其移除。

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    [controller.view removeFromSuperview]; 

} 

我還是建議使用

[self.navigationController presentModalViewController:picker animated:YES];對於目前MFMailComposeViewController,

,並使用[self dismissModalViewControllerAnimated:YES];予以駁回。

相關問題