iOS 11 presentViewController going behind presenting controller

Viewed 1178

I am having a strange issue where I am just doing a simple presenting modal view controller. MFMailComposeViewController to be exact. However, it is appearing behind the presenting controller and thus you can not send any email or type. You can see the "Cancel" button on the UINavigationBar on the mail composer, but that pops the UIAlertController behind the presenting controller. How has this happened? Is it an iOS 11 issue? I am also getting similar behaviour for UIAlertControllers too.

Also, if I press send and press my button to pop up another Composer, it works as normal. It is just the first one.

Please see attached image I got from Xcode.

enter image description here

MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
mailer.modalPresentationStyle = UIModalPresentationFormSheet;
[mailer setSubject:@"subject Feedback"];
[mailer setToRecipients:@[@"email address"]];
[mailer setMessageBody:@"" isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];

Edit: Adding the controller for more information.

#import "AboutViewController.h"
#import <MessageUI/MessageUI.h>


@interface AboutViewController () <MFMailComposeViewControllerDelegate>
@property (nonatomic, strong) IBOutlet UIView *contentView;
@end

@implementation AboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"About this app";
    _contentView.layer.cornerRadius = 10.;
    _contentView.layer.shadowColor = [UIColor blackColor].CGColor;
    _contentView.layer.shadowRadius = 3.;
    _contentView.layer.shadowOpacity = 0.4;
    _contentView.layer.shadowOffset = CGSizeMake(3., 3.);
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sendFeedbackEmail:(id)sender {
    if ([MFMailComposeViewController canSendMail]){
        dispatch_async(dispatch_get_main_queue(), ^{
            MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
            mailer.mailComposeDelegate = self;
            mailer.modalPresentationStyle = UIModalPresentationFormSheet;
            [mailer setSubject:@"Feedback"];
            [mailer setToRecipients:@[@"email@email.com"]];
            [mailer setMessageBody:@"" isHTML:NO];
            [self presentViewController:mailer animated:YES completion:nil];

        });
    } else {
        NSLog(@"Nope");
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [controller dismissViewControllerAnimated:YES completion:nil];
}

Edit 2:

I believe I have found the answer. I hope this may help anyone who encounter the same issue. Thank you for all the replies, it helped me find the answer. Thank you @Mert Buran for the delegate idea. This showed me that it had a different transition delegate the first time and the one I wanted the second time.

The issue was that the navigationController pushed the new controller before dismissing a controller I had on top (a menu controller). A simple fix but because it is not evident at the start and no error logs, it was difficult to pin point.

1 Answers
Related