Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - MFMailComposeViewController delegate incompatible type

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.

like image 400
serverpunk Avatar asked Mar 17 '12 20:03

serverpunk


1 Answers

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.

like image 196
mattjgalloway Avatar answered Oct 23 '22 21:10

mattjgalloway