我遇到了一个奇怪的问题,我只是简单地展示模态视图控制器。确切地说,是
此外,如果我按下发送并按下我的按钮以弹出另一个编辑器,它会像往常一样工作。只有第一个出现问题。
请查看我从 Xcode 得到的附加图像。
MFMailComposeViewController
。然而,它出现在呈现控制器的后面,因此您无法发送电子邮件或输入任何内容。您可以在邮件编辑器的 UINavigationBar
上看到“取消”按钮,但是这会弹出在呈现控制器后面的 UIAlertController
。为什么会出现这种情况?这是一个 iOS 11 的问题吗?我也遇到了类似 UIAlertController
行为的问题。此外,如果我按下发送并按下我的按钮以弹出另一个编辑器,它会像往常一样工作。只有第一个出现问题。
请查看我从 Xcode 得到的附加图像。
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];
编辑:添加控制器以获取更多信息。
#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];
}
编辑2:
我相信我已经找到了答案。希望这可以帮助任何遇到相同问题的人。感谢所有的回复,它们帮助我找到了答案。感谢 @Mert Buran 提供的代理想法。这向我展示了第一次有不同的过渡代理和我想要的第二次。
问题是navigationController在解除我最上面的控制器(一个菜单控制器)之前推送了新的控制器。这是一个简单的修复,但因为一开始并不明显,也没有错误日志,所以很难确定问题所在。
mailer.transitioningDelegate
并观察谁真正呈现了mailer
,因为[self presentViewController:...]
不能保证self
将呈现另一个视图控制器。 - Mert Buran