[英]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.