Recipients field of MFMessageComposeViewController doesn't show in iOS 7

时光毁灭记忆、已成空白 提交于 2019-11-27 02:11:51

问题


The code below works fine in iOS 5/6. In iOS 7, it looks like this (red oval for emphasis).

Code:

if ([MFMessageComposeViewController canSendText]) {
    self.messageComposer = [MFMessageComposeViewController new];
    self.messageComposer.recipients = @[number];
    self.messageComposer.messageComposeDelegate = self;
    [self presentViewController:self.messageComposer
                       animated:YES
                     completion:nil];
}

Question: This is simple code. Is there some other external property, perhaps of the presenting view controller, that is affecting this? Anyone have a fix or workaround?

thanks.


回答1:


I've found that the MFMessageComposeViewController's recipient field seems to take some of it's appearance from the UINavigationBar appearance proxy in iOS7. To work around this, I've done the following in my apps:

  1. Create an empty custom UINavigationController subclass, which doesn't override any of UINavigationController's methods.
  2. Use this custom UINavigationController subclass as a marker for any navigation controllers that I want to have custom appearance, by setting the custom class on the identity inspector in IB:

  3. In my app delegate, set up the appearance of navigation bars like this:

    [[UINavigationBar appearanceWhenContainedIn:[MyCustomNavigationController class], nil] ...];
    

This ensures that I get the navigation bar appearance I want in the controllers I want to customize, but preserves the standard navigation bar (and related) appearance in other controllers (like MFMessageComposeViewController). Here's a screenshot; note the standard appearance of MFMessageComposeViewController, with the custom navigation bar appearance on the popover in the background:




回答2:


I faced same problem and here is my solution-

Before presenting your message composer( [self presentViewController:messageComposer animated:YES completion:nil]; ) set

[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

and in delegate method

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {
     UIImage *backgroundImage = [UIImage imageNamed:@"Navigation Bar"];
    [[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
    [self dismissViewControllerAnimated:YES completion:nil];
}

Thats all!!



来源:https://stackoverflow.com/questions/19105591/recipients-field-of-mfmessagecomposeviewcontroller-doesnt-show-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!