Search code examples
iosiphoneobjective-cuiappearancemfmessagecomposeviewcontroller

Strange behavior with message composer on iOS 7


I'm working on an app that sends email and texts from the user's contact list.

I have a view controller that presents either a MFMessageComposeViewController or MFMailComposeViewController, with the proper delegates setup. However, the UI that appears in the composer seems offset and incorrect.

Here's the code to present the message composer:

if ([MFMessageComposeViewController canSendText]) {
    MFMessageComposeViewController *composer = [[MFMessageComposeViewController alloc] init];
    composer.messageComposeDelegate = self;
    composer.recipients = [NSArray arrayWithObject:[self unformattedPhoneNumber:number]];
    [self presentViewController:composer animated:YES completion:nil];
}

Pretty simple stuff. However, when the modal view controller is presented, it looks like this:

The messed up contact picker text field in the message compose view controller

The contact picker text field (where you can type in users by name or number), appears briefly against the black background, but then animates up to be hidden behind the navigation bar. Even stranger, the contact text field starts as the first responder, so you can still type into it, and here is the result when you start searching for contacts:

Typing in contacts here

I've used the mail and message composer plenty of times before in previous apps, but this is a bug I've never seen before. I've tried presenting the VC in a separate thread, validating the phone number I'm using, and nothing seems to change it. I noticed that if I change my window.backgroundColor to [UIColor whiteColor], the contact text field has a white background, so it seems like that portion of the message view controller is transparent. I have a similar issue with the mail composer.

Anyone experienced anything like this or have any thoughts?


Solution

  • Are you using UIAppearance to customize appearance in your app? It appears that you are since the navigation bar style on that compose view is not the default.

    This may be caused by customizing some of the views that these internal components use, which cause some of them to break. To test this out, get rid of all of your UIAppearance code and try again to see if it still occurs.

    If that is the case, you will need to work around it by narrowing down your UIAppearance calls with appearanceWhenContainedIn: so that the internal classes are not affected.