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.

serverpunk
  • 10,665
  • 15
  • 61
  • 95

1 Answers1

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.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110
  • 2
    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 :-). – mattjgalloway Mar 17 '12 at 20:47