简体   繁体   English

呈现MFMessageComposeViewController然后将其关闭后,呈现视图无法正确显示

[英]Presenting view not appearing properly after MFMessageComposeViewController is presented and then dismissed

I have a View Controller which displays a table view. 我有一个显示表视图的视图控制器。 The VC calls another VC to display the send SMS view to the user, the code for this SMS VC is: VC调用另一个VC向用户显示发送SMS视图,此SMS VC的代码为:

- (void) sendSMSWithBody: (NSString*) body andRecipients: (NSArray*) recipients
{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if ([MFMessageComposeViewController canSendText])
    {
        controller.messageComposeDelegate = self;
        controller.body = body;
        controller.recipients = recipients;
        [[UIApplication sharedApplication].delegate.window.rootViewController addChildViewController:self];
        [self presentModalViewController:controller animated:YES];
    }
}

- (void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissModalViewControllerAnimated:YES];
    [[UIApplication sharedApplication].delegate.window.rootViewController removeFromParentViewController];    
}

(I know the call to sharedApplication is a bit hacky, but it will suffice for now. the rootViewController is a UINavigationController which has its root controller set to the table view controller) (我知道对sharedApplication的调用有点hacky,但现在就足够了。rootViewController是一个UINavigationController,其根控制器设置为表视图控制器)

I am invoking the SMS VC from the table VC like so: 我从表VC调用SMS VC,如下所示:

- (void ) viewDidAppear:(BOOL)animated
{
    static BOOL presentedSMSVC = NO;
    if (!presentedSMSVC)
    {
        SendSMSController *sendSMS = [[SendSMSController alloc] init];
        [sendSMS sendSMSWithBody:@"body" 
                   andRecipients:[NSArray arrayWithObject:@"123456789"]];
        presentedRegisterVC = YES;
    }
}

The problem is that after the user sends the SMS the table view cells are not displaying. 问题在于用户发送SMS后,表格视图单元格未显示。

I thought maybe I need to refresh the view/table so I added a protocol callback from the 2nd VC to the first which gets invoked when the user sends the SMS, and then within the callback call [self.tableView reloadData] But it made no difference. 我以为可能需要刷新视图/表,所以我在第2个VC上添加了第一个VC的协议回调,当用户发送SMS时会调用该协议,然后在回调调用[self.tableView reloadData]中,但是它没有区别。

So I got rid of the intermediary class and edited the table view to display the SMS view directly like this: 因此,我摆脱了中介类,并编辑了表格视图以直接显示SMS视图,如下所示:

- (void ) viewDidAppear:(BOOL)animated
   {
    static BOOL presentedRegisterVC = NO;
    if (!presentedRegisterVC)
    {
        MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
        if ([MFMessageComposeViewController canSendText])
        {
            controller.messageComposeDelegate = self;
            controller.body = @"body";
            controller.recipients = [NSArray arrayWithObject:@"12345678"];
            [self presentModalViewController:controller animated:NO];
        }
    }
}


- (void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissModalViewControllerAnimated:NO];    
}

But now the MFMessageComposeViewController doesn't dismiss (although messageComposeViewController:didFinishWithResult: does get called) 但是现在MFMessageComposeViewController并没有关闭(尽管messageComposeViewController:didFinishWithResult:确实被调用了)

What is the problem with both approaches? 两种方法都有什么问题? Thanks 谢谢

I faced a similar UI issue. 我遇到了类似的UI问题。 My case was: The controller, let's say controller A, in which I had written the code to present and dismiss the MFMessageComposeController, was not being used directly as the active controller rather I was using A.view as a subview over another controller, say controller B. So writing the following was distorting the view: 我的情况是:控制器(假设我编写了代码来呈现和关闭MFMessageComposeController的控制器A)没有直接用作活动控制器,而是使用A.view作为另一个控制器的子视图,例如控制器B。因此编写以下内容会使视图失真:

[self presentViewController:composeVC animated:YES completion:nil];

But then writing the following solved my issue: 但是随后编写以下代码解决了我的问题:

[self.customTabbarNavigation presentViewController:composeVC animated:YES completion:nil];

The customTabbarNavigation, was the controller B, ans was actually the navigation controller which was active when controller A's view was visible. customTabbarNavigation是控制器B,而ans实际上是导航控制器,当控制器A的视图可见时,它是活动的。

Same change had to be made for dismissing the composeVC. 解散composeVC必须进行相同的更改。

For the second variant, I changed to: 对于第二个变体,我更改为:

[self presentViewController: controller animated: YES completion:nil]; [self presentViewController:动画控制器:是完成:无]; [self dismissViewControllerAnimated:YES completion:nil]; [self dismissViewControllerAnimated:YES完成:无];

And that worked, haven't tried applying to the first method. 而且行之有效,没有尝试将其应用于第一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS /自动版式:取消已演示的控制器后,更改为演示视图 - IOS/Autolayout: Change to Presenting View After Presented Controller Dismissed 调用viewWillAppear时显示视图控制器的问题被解除 - Issue with calling viewWillAppear of presenting view controller when presented one is dismissed 关闭UIPopoverController后呈现视图控制器 - Presenting a View Controller after a UIPopoverController is dismissed WKWebView 操作表在被解散后解散呈现视图控制器 - WKWebView action sheet dismisses the presenting view controller after being dismissed 所有呈现的视图控制器都不会被解雇 - All the presented view controllers are not dismissed iOS –收到UILocalNotification后显示MFMessageComposeViewController - iOS – Presenting MFMessageComposeViewController after receiving a UILocalNotification 检测何时关闭呈现的视图控制器 - Detect when a presented view controller is dismissed 模态显示/关闭视图控制器时通知? - Notification when view controller is presented modally/dismissed? UIMenuController在显示后立即被解雇 - UIMenuController is getting dismissed immediately after being presented 为什么我的视图控制器(从故事板中以模态方式呈现)在被解雇后不会被释放? - Why does my view controller (presented modally from a storyboard segue) not get released after being dismissed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM