Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MFMailComposeViewController in storyboard does not work

In storyboard I can setup a segue from a button to a UIViewController and make it appear modally. This works fine. However when I change the class in storyboard from UIViewController to MFMailComposeViewController, it does not work at all. All that appears is a navigation bar at the top with the rest of the display being filled with black. Am I taking the wrong approach?

like image 747
Alex Bamb Avatar asked Jan 02 '12 17:01

Alex Bamb


2 Answers

I had a similar problem with ABPeoplePickerNavigationController and I could not seem to figure out what the problem was either. You can either

  1. Fall back to a IBAction and create the MFMailComposeViewController instance your self and display it.

  2. If you want to keep using Storyboards, which I think is desirable then you might create a wrapper-class that internally instantiates the MFMailComposeViewController and then functions as a proxy object and thus propagates viewDid*** and viewWill***-methods to the wrapped class and also returning the wrapped VC's view in a readonly view property... You get the idea.

like image 170
Besi Avatar answered Nov 10 '22 09:11

Besi


In addition to the answer by Besi:

  1.  
  2.  
  3. Subclass MFMailComposeViewController and override initWithCoder: method.

Example:

-(id)initWithCoder:(NSCoder *)aDecoder
{
    return [super init];
}

Then it will work with storyboards, but I think your outlets / tags / other definitions from storyboard scene won't be applied (you have to configure mail composer inside your prepareForSegue:sender: method).

like image 2
vectoroc Avatar answered Nov 10 '22 08:11

vectoroc