Arbitur
Arbitur

Reputation: 39091

MFMailComposeViewController wipes rootViewcontroller

Im making sending an email available for the user with this code:

MFMailComposeViewController *vc = [MFMailComposeViewController new];
[vc setSubject:@"Test Subject"];
[vc setMessageBody:@"Test Body" isHTML:NO];
[vc setMailComposeDelegate:self];
[self presentViewController:vc animated:YES completion:nil];

This opens a ViewController with all the stuff you need to sen an email, but it completely wipes everything from the ViewController the user is previously on. It only removes the subviews because the root view is still there because the backgroundColor is still the same.

I have already tried initWithRootViewController: but it crashes.

What is happening?

Upvotes: 0

Views: 141

Answers (2)

Arbitur
Arbitur

Reputation: 39091

I found the bug... It wasn't in the code above. It seems the viewWillDissapear: is getting called when presenting the mailVC :/

In there I have code to remove every subview, so yeah, found the problem thanks anyways for those who answered and sorry for the inconvenience.

Upvotes: 1

Odrakir
Odrakir

Reputation: 4254

I'm not sure what you mean by "completely wipes everything". But suposing this is for iPad (and not iPhone), when presenting a view controller it goes full screen by default. If you want to change that, you have to set the modalPresentationStyle of the presented view controller (MFMailComposeViewController in your case)

Your code would look like this:

MFMailComposeViewController *vc = [MFMailComposeViewController new];
[vc setSubject:@"Test Subject"];
[vc setMessageBody:@"Test Body" isHTML:NO];
[vc setMailComposeDelegate:self];
vc.modalPresentationStyle = UIModalPresentationFormSheet; //You can use custom size too
[self presentViewController:vc animated:YES completion:nil];

Upvotes: 0

Related Questions