我有一个奇怪的问题,我只是做一个简单的呈现模态视图控制器。确切地说MFMailComposeViewController
。但是,它出现在呈现控制器后面,因此您无法发送任何电子邮件或类型。您可以在邮件编辑器上的UINavigationBar
上看到“取消”按钮,但会弹出显示控制器后面的UIAlertController
。这是怎么发生的?这是iOS 11问题吗?我对UIAlertController
也有类似的行为。
此外,如果我按下发送并按下我的按钮以弹出另一个Composer,它将正常工作。这只是第一个。
请参阅我从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在解除我顶上的控制器(菜单控制器)之前推动了新的控制器。一个简单的修复,但因为它在开始时并不明显,没有错误日志,所以很难确定。
答案 0 :(得分:0)
我会在self.definesPresentationContext = YES
中尝试viewDidLoad
。见https://developer.apple.com/documentation/uikit/uiviewcontroller/1621456-definespresentationcontext