【问题标题】:Composing mail in iOS 7 : Assertion failure in -[MFComposeSubjectView layoutSublayersOfLayer:]在 iOS 7 中撰写邮件:-[MFComposeSubjectView layoutSublayersOfLayer:] 中的断言失败
【发布时间】:2013-12-12 17:49:03
【问题描述】:

我目前在使用 iOS7 和 MFMailComposeViewController 时遇到问题。有时(经常但不总是),我在呈现MFMailComposeViewController 时会出现以下崩溃:

** * -[MFComposeSubjectView layoutSublayersOfLayer:] 中的断言失败,/SourceCache/UIKit/UIKit-2903.23/UIView.m:8540

这是我展示控制器的方式:

if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController* mailVC = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        mailVC.mailComposeDelegate = self;

        [mailVC setSubject:@"blablabla"]];
        [mailVC setMessageBody:@"blablabla" isHTML:NO]; 
        mailVC.modalPresentationStyle = UIModalPresentationFormSheet;
        mailVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

        if(isIpad) {
            [sharedParentViewController presentViewController:mailVC animated:YES completion:nil];
        } else {
            [sharedNavigationViewController presentViewController:mailVC animated:YES completion:nil];
        }
    }

sharedParentViewControllersharedNavigationViewController 是定义的宏,用于访问应用程序中任何地方的根视图控制器。

我在所有异常上都设置了一个断点,但不幸的是,它永远不会中断。

使用 iOS6 和 iOS5,一切正常,知道我可以尝试解决这个问题吗?

编辑:

这是崩溃日志:

Stack Trace

Auto Layout still required after executing -layoutSubviews. MFComposeSubjectView's implementation of -layoutSubviews needs to call super.

0   CoreFoundation                      0x3099ff4b <redacted> + 130
1   libobjc.A.dylib                     0x3b1366af objc_exception_throw + 38
2   CoreFoundation                      0x3099fe25 <redacted> + 0
3   Foundation                          0x31347fe3 <redacted> + 90
4   UIKit                               0x33112e63 <redacted> + 538
5   QuartzCore                          0x32d99c6b <redacted> + 142
6   QuartzCore                          0x32d9547b <redacted> + 350
7   QuartzCore                          0x32d9530d <redacted> + 16
8   QuartzCore                          0x32d94d1f <redacted> + 230
9   QuartzCore                          0x32d94b2f <redacted> + 314
10  QuartzCore                          0x32d8e85d <redacted> + 56
11  CoreFoundation                      0x3096b1cd <redacted> + 20
12  CoreFoundation                      0x30968b71 <redacted> + 284
13  CoreFoundation                      0x30968eb3 <redacted> + 730
14  CoreFoundation                      0x308d3c27 CFRunLoopRunSpecific + 522
15  CoreFoundation                      0x308d3a0b CFRunLoopRunInMode + 106
16  GraphicsServices                    0x355c7283 GSEventRunModal + 138
17  UIKit                               0x33177049 UIApplicationMain + 1136
18  teleobs                             0x00037921 main + 116
19  teleobs                             0x000378a8 start + 40

【问题讨论】:

  • 您是否使用外观选择器来设置导航栏颜色?如果你这样做,尽量不要使用图像来生成颜色!
  • @ChamiraFernando 不,我现在检查了,根本没有使用 UIAppearance 选择器。
  • 或者你使用图像改变导航控制器的颜色?我的意思是 [uicolor colorWithPatternImage] ?
  • @ChamiraFernando 我不使用任何图案图像。在导航控制器上执行的唯一自定义是这个:self.navigationBar.tintColor = [UIColor whiteColor]; [self.navigationBar setTranslucent:NO];
  • 很难说它发生在哪里……你能看到整个崩溃日志吗?

标签: ios objective-c cocoa-touch ios7 mfmailcomposeviewcontroller


【解决方案1】:

我猜这个问题是因为:

  1. 已启用自动布局(在情节提要等中)
  2. UIView 类别(或更多)与- (void)layoutSubviews 的调用

检查所有UIView 类别(在您的项目中)如果它调用- (void)layoutSubviews,请尝试评论此调用以进行测试。或者只是关闭自动布局

【讨论】:

    【解决方案2】:

    可能是因为您尝试使用initWithNibName:bundle: 而不是initinitialize MFMailComposeViewController。以这种方式尝试,它应该可以工作。

    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;
    [mailComposer setSubject:emailTitle];
    [mailComposer setMessageBody:message isHTML:NO];
    

    如果您的macros 有问题,您最好先尝试以正常方式拨打MFMailComposeViewController

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

    没有开关,如果它可以工作,你可以看看如何切换它。

    【讨论】:

    • 一个普通的init 打电话给[self initWithNibName:nil bundle:nil]
    【解决方案3】:

    就我而言,问题是当UIActionSheet 仍然出现时,我尝试presentViewController:。它有自己的窗口,覆盖我们的窗口。我添加了一个小的延迟 0.1f 秒,并在 dispatch_after 块中调用了 MFMailComposeViewController 的呈现。之后它开始正常工作。

    如果0.1f 不起作用,请尝试将延迟增加到0.3f

    我认为UIAlertView 和其他使用这些自己的窗口进行演示的类也会遇到同样的问题。

    这个解决方案并不优雅,所以如果有人有更好的决定,我很乐意知道。

    【讨论】:

      【解决方案4】:

      MFComposeSubjectView类中,你重写了-layoutSubviews但不调用[super layoutSubviews]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多