在segue之前的MFMailComposeViewController模态视图阻止了segue

时间:2013-02-05 07:13:10

标签: iphone ios modalviewcontroller segue

我正在使用我提出的模态视图中的按钮单击:

UIAlertView *   alert =
    [[UIAlertView alloc] initWithTitle: title
                               message: reason
                              delegate: self
                     cancelButtonTitle: @"New"
                     otherButtonTitles: @"View", nil];
    [alert show];

点击下面带有故事板的iPhone的“clickedButtonAtIndex”方法中的“查看”按钮,我称之为“[self performSegueWithIdentifier:@”ModalSaleDetail1“sender:self];”

- (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
{
    if ([alertView.title isEqualToString: @"Successful"]) {
        switch (buttonIndex) {
            case 0:     //  New transaction
            {
                if ([self.currentSale.lastStatus isEqualToString:@"approved"]) {
                    [self displayComposerSheet];
                }
                [self clearTransaction:nil];
                break;
            }
            case 1:     //  View Transaction Details
            {
                NSLog(@"User wants to view transaction details.");
                self.currentSale.cardNumber = self.currentSale.cardNumber.bulletRedacted;
                self.cardNumberField.text = self.displayCardNumberView.text = self.currentSale.cardNumber;

                if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {  // device is iPad
                    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
                    UISplitViewController *splitVC = (UISplitViewController *)(self.tabBarController.selectedViewController);
                    UINavigationController *navC = [[splitVC viewControllers] lastObject];
                    APSaleDetailViewController *salesDVC = (APSaleDetailViewController *)navC.topViewController;
                    // If came here from new sale set to self.currentSale, otherwise do not
                    if (!salesDVC.currentSale) {
                        salesDVC.currentSale = self.currentSale;
                    }
                    salesDVC.apNewTVC = self;
                    if ([self.currentSale.lastStatus isEqualToString:@"approved"]) {
                        [self displayComposerSheet];
                    }
                } else {                                                                        // device is iPhone
                    if ([self.currentSale.lastStatus isEqualToString:@"approved"]) {
                        [self displayComposerSheet];
                    }
                    [self performSegueWithIdentifier:@"ModalSaleDetail1" sender:self];
                }
                break;
            }
            default:
            {
                NSAssert1(NO, @"Unknown alert button %d", buttonIndex);
            }
        }
    } else if .....

在我使用MFMailComposeViewController实现我的电子邮件发件人之前,这个segue工作正常。

我使用以下代码显示MFMailComposeViewController的模态视图:

// Displays an email composition interface. Populates all the Mail fields.
-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Receipt for credit card transaction"];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:self.currentSale.emailAddress];

    [picker setToRecipients:toRecipients];

    UIGraphicsBeginImageContext(self.view.frame.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData * imageData = UIImageJPEGRepresentation(image, 1.0);

    if ( [MFMailComposeViewController canSendMail] ) {
        NSString *emailBody = @"Your credit card transaction summary and signature:";
        [picker setMessageBody:emailBody isHTML:NO];
        [picker addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment"];
        NSData *myData = UIImagePNGRepresentation(self.signatureImage);
        [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"Autograph"];
        [self presentModalViewController:picker animated:YES];
    }
}

现在,当调用[self displayComposerSheet]后调用[self performSegueWithIdentifier:@“ModalSaleDetail1”sender:self]时,不会发生segue。电子邮件作曲家表格正确显示,但在我发送或取消后,不会发生segue。如果我注释掉[self displayComposerSheet]的调用,则segue应该发生(但当然没有电子邮件)。

顺便说一句,iPad代码可以正常使用[self displayComposerSheet]调用,因为它不使用segues。

在提交模态对话框后,是否立即执行segue?

我正在构建适用于iOS 6.1的Xcode 4.6并部署到iOS 5.1。我的iPhone运行5.1.1,我的iPad运行6.1。

2 个答案:

答案 0 :(得分:0)

  • (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender NS_AVAILABLE_IOS(5_0);

你知道,这个界面在iOS 5中不可用

答案 1 :(得分:0)

我知道,这并不能解决你对Segues的问题,但是如果你想回到之前的View Controller,试试这个:

[self dismissViewControllerAnimated:YES completion:nil];