iPhone - MFMailComposeViewController delegate incompatible type
Asked Answered
C

1

16

I have a view controller which opens an MFMailComposeViewController modally. When I try to set the mail view controller's delegate to the parent view controller, I get this warning:

Assigning to 'id<UINavigationControllerDelegate>' from incompatible
type 'MoreViewController *__strong'

The parent view controller definitely has MFMailComposeViewControllerDelegate in its interface declaration and is implementing the delegate method -mailComposeController: didFinishWithResult:error: as follows:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    NSLog(@"Delegate called");
}

I really don't understand why the parent view controller is being recognized as a UINavigationControllerDelegate, as I don't implement those methods nor do I declare it as such. I wouldn't be so worried about it but the delegate method never gets called, so I'm guessing this "mismatch" is part of the problem.

If it helps, this is how I am initting the mail view controller, in viewDidLoad:

// MAIL
self.mail = [[MFMailComposeViewController alloc] init];
self.mail.delegate = self;

Thanks in advance for any thoughts you may have.

Cellulose answered 17/3, 2012 at 20:43 Comment(0)
F
31

You want to set mailComposeDelegate rather than delegate:

self.mail.mailComposeDelegate = self;

Basically, you were setting the delegate which because MFMailComposeViewController inherits from UINavigationController, means that delegate needs to implement UINavigationControllerDelegate.

Fivefinger answered 17/3, 2012 at 20:45 Comment(1)
No probs. That's a mistake I've made many many times and still do to this day when I'm a bit sleepy! You're not alone :-).Fivefinger

© 2022 - 2024 — McMap. All rights reserved.