0
votes

I'm using a button-click from a modal view which I put up with:

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

When clicking the "View" button in the "clickedButtonAtIndex" method below for iPhone with storyboards, I called "[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 .....

This segue worked fine before I implemented my email sender with MFMailComposeViewController.

I used the following code to display a modal view for 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];
    }
}

Now, when [self performSegueWithIdentifier:@"ModalSaleDetail1" sender:self] gets called after just having called [self displayComposerSheet] no segue takes place. The email composer sheet gets displayed properly, but after I send or cancel it, the segue doesn't happen. If I comment out the call to [self displayComposerSheet] the segue happens as it should (but of course without the email).

By the way, the iPad code works just fine with the [self displayComposerSheet] call because it doesn't use segues.

Does performing a segue immediately after presenting a modal dialog work in general?

I'm building in Xcode 4.6 for iOS 6.1 and deploying to iOS 5.1. My iPhone runs 5.1.1 and my iPad runs 6.1.

2

2 Answers

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

you see, this interface is not available in iOS 5

0
votes

I know, this does not solve your problem with Segues but if you are trying to go back to the previous View Controller, try this:

[self dismissViewControllerAnimated:YES completion:nil];