MFMailComposeViewController:解雇后与UITextField和UIAlertController有关的问题

时间:2014-11-15 03:10:50

标签: ios objective-c mfmailcomposeviewcontroller uialertcontroller

在我的应用程序中使用MFMailComposeViewControlle r之后我遇到两个问题:

  1. 解除MFMailComposeViewController后,我的初始UITextField上的ViewController文字已清除
  2. 尝试显示UIAlertController以表示MFMailComposeResult时,无法显示日志中的错误。
  3. 问题1:这是我的MFMailComposeViewController代码。这是UIAlertControllerUIAlertControllerStyleActionSheet)的操作。

        UIAlertAction *email = [UIAlertAction
                            actionWithTitle:@"Email the link"
                            style:UIAlertActionStyleDefault
                            handler:^(UIAlertAction * action)
                            {
    
                                // composes new mail message with link
                                NSString *messageBody = self.link.text;
    
                                MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
                                mc.mailComposeDelegate = self;
                                [mc setMessageBody:messageBody isHTML:NO];
    
    
                                // customises UI to match application
                                [[mc navigationBar] setTintColor:[UIColor whiteColor]];
                                [self presentViewController:mc animated:YES completion:^{
                                    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
                                    [self setNeedsStatusBarAppearanceUpdate];
                                }];
    
                                [view dismissViewControllerAnimated:YES completion:nil];
    
                            }];
    

    问题2:这是我为每个相关UIAlertController显示相应MFMailComposeResult的代码。

    - (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        switch (result)
        {
            case MFMailComposeResultCancelled:{
    
                UIAlertController *alert=   [UIAlertController
                                             alertControllerWithTitle:@"SearchMe"
                                             message:@"The composition of this email has been cancelled."
                                             preferredStyle:UIAlertControllerStyleAlert];
    
                UIAlertAction *done = [UIAlertAction
                                       actionWithTitle:@"Done"
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction * action)
                                       {
                                           [alert dismissViewControllerAnimated:YES completion:nil];
    
                                       }];
    
    
                [alert addAction:done];
                [self presentViewController:alert animated:YES completion:nil];
    
                [alert dismissViewControllerAnimated:YES completion:nil];
    
    
        }
    
                break;
            case MFMailComposeResultSaved:{
    
                UIAlertController *alert=   [UIAlertController
                                             alertControllerWithTitle:@"SearchMe"
                                             message:@"The composition of this email has saved as a draft."
                                             preferredStyle:UIAlertControllerStyleAlert];
    
                UIAlertAction *done = [UIAlertAction
                                       actionWithTitle:@"Done"
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction * action)
                                       {
                                           [alert dismissViewControllerAnimated:YES completion:nil];
    
                                       }];
    
    
                [alert addAction:done];
                [self presentViewController:alert animated:YES completion:nil];
    
                [alert dismissViewControllerAnimated:YES completion:nil];
    
    
            }
    
                break;
            case MFMailComposeResultSent:{
    
                UIAlertController *alert=   [UIAlertController
                                             alertControllerWithTitle:@"SearchMe"
                                             message:@"The composition of this email has been sent."
                                             preferredStyle:UIAlertControllerStyleAlert];
    
                UIAlertAction *done = [UIAlertAction
                                       actionWithTitle:@"Done"
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction * action)
                                       {
                                           [alert dismissViewControllerAnimated:YES completion:nil];
    
                                       }];
    
    
                [alert addAction:done];
                [self presentViewController:alert animated:YES completion:nil];
    
                [alert dismissViewControllerAnimated:YES completion:nil];
    
            }
    
    
                break;
            case MFMailComposeResultFailed:
            {
    
                UIAlertController *alert=   [UIAlertController
                                             alertControllerWithTitle:@"SearchMe"
                                             message:@"The composition of this email has failed. Please try again."
                                             preferredStyle:UIAlertControllerStyleAlert];
    
                UIAlertAction *done = [UIAlertAction
                                       actionWithTitle:@"Done"
                                       style:UIAlertActionStyleDefault
                                       handler:^(UIAlertAction * action)
                                       {
                                           [alert dismissViewControllerAnimated:YES completion:nil];
    
                                       }];
    
    
                [alert addAction:done];
                [self presentViewController:alert animated:YES completion:nil];
    
                [alert dismissViewControllerAnimated:YES completion:nil];
            }
    
    
    
                break;
            default:
                break;
        }
    
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
    

    日志中给出的错误是:

    Warning: Attempt to present <UIAlertController: 0x14ed58b90> on <ViewController: 0x14ee1f7f0> whose view is not in the window hierarchy!
    

0 个答案:

没有答案