uiviewcontroller - iOS8 中的 MFMessageComposeViewController 问题

标签 uiviewcontroller uikit ios8 mfmessagecomposeviewcontroller messageui

我在 iOS8 中遇到了 MFMessageComposeViewController 的一个奇怪错误,该错误只能在我自己的应用程序中重现。它现在正在影响 App Store 中的应用程序,该应用程序是使用在 iOS8 上运行的 iOS7 SDK 构建的,以及我自己的测试设备(iPhone 和 iPad)中使用 iOS8 SDK 构建的应用程序

问题是,当我调出 MFMessageComposeViewController 时,它显示的 Controller 不再带有文本字段或发送按钮。我没有在 iOS7 和 iOS8 之间更改我的代码,所以不确定为什么会发生这种情况。代码本身非常简单:

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
[picker setRecipients: @[@"5551112222"]];
[picker setBody: @"Test"];

[self presentViewController:picker animated:YES completion: ^{
    NSLog(@"MFMessageComposeViewController completion handler"); 
}];

这就是它的样子:

enter image description here

对于我可以尝试的解决方法有什么想法吗?我尝试在完成处理程序中设置文本字段和收件人;尝试在最顶层的 View Controller 上调用becomeFirstResponder;没有运气。再说一遍,这在 iOS7 中工作得非常好。

编辑:

所以我从此链接找到了Apple自己的MFMessageComposeViewController示例代码:https://developer.apple.com/library/ios/samplecode/MessageComposer/Listings/MessageComposerViewController_m.html

当我构建并运行此应用程序时,MFMessageComposeViewController 显示完美,并且预填充电话号码和文本字段也有效。但是,当我将他们的文件复制到我的应用程序中,将他们的 Storyboard设为我的主 Storyboard,按下“撰写短信”按钮时,我看到了同样的问题!

这是怎么回事?很困惑。我自己的应用程序中的某些配置是否会阻止消息编辑器正确显示?

最佳答案

最后,在拆掉我的大部分应用程序后,我终于找到了问题所在。事实证明,我重写了类别中的 UIViewController 系统方法(而不是子类):

@implementation UIViewController (UIViewController_Additions)
-(BOOL)canBecomeFirstResponder {
    return YES;
}

这在 iOS7 之前一直工作正常,但在 iOS8 和“MFMessageComposeViewController”中内部一定发生了一些变化。 “4岁老黑客来咬你屁股”的案例

苹果也不鼓励这种做法,根据此链接(尽管我找不到原始的苹果来源):https://stackoverflow.com/a/14259595/145552

关于uiviewcontroller - iOS8 中的 MFMessageComposeViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25924574/

相关文章:

swift - 如何仅在 Swift 中将一个 View Controller 的方向锁定为纵向模式

ios - 改变 Swift 中的 VC 问题。如何在标签栏 Controller 的 View 之间传递数据?

ios - 父级 UIViewControllers 是否应该将 didRotateFromInterfaceOrientation 传播给子级?

ios - iOS8 中的 UIWindow 无法正确旋转

ios - iPad UISplitViewController : Expand master instead of detail full screen?

iphone - 为什么 -animateWithDuration :delay:options:animations:completion: blocking the UI?

ios - 是否可以更改具有不同类的对象的类类型?

ios - UISegmentedControl 辅助功能模式样式

ios - MPMoviePlayerController - 检测按下 Next/Prev 按钮

ios - 如何在 iOS 8 的模态视图 Controller 中强制纵向显示?