我有一个 View Controller ,它以模态方式打开 MFMailComposeViewController。当我尝试将邮件 View Controller 的委托(delegate)设置为父 View Controller 时,我收到此警告:
Assigning to 'id<UINavigationControllerDelegate>' from incompatible
type 'MoreViewController *__strong'
父 View Controller 在其接口(interface)声明中肯定有 MFMailComposeViewControllerDelegate 并且正在实现委托(delegate)方法 -mailComposeController: didFinishWithResult:error: 如下:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSLog(@"Delegate called");
}
我真的不明白为什么父 View Controller 被识别为 UINavigationControllerDelegate,因为我没有实现这些方法,也没有这样声明它。我不会那么担心,但是永远不会调用委托(delegate)方法,所以我猜这个“不匹配”是问题的一部分。
如果有帮助,这就是我在 viewDidLoad 中初始化邮件 View Controller 的方式:
// MAIL
self.mail = [[MFMailComposeViewController alloc] init];
self.mail.delegate = self;
提前感谢您的任何想法。
最佳答案
您想设置 mailComposeDelegate 而不是 delegate:
self.mail.mailComposeDelegate = self;
基本上,您正在设置 delegate,因为 MFMailComposeViewController 继承自 UINavigationController,这意味着 delegate 需要实现 UINavigationControllerDelegate。
关于iPhone - MFMailComposeViewController 委托(delegate)不兼容的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9753555/