问题描述
当我出示 MFMailComposeViewController
时,我收到以下崩溃:
I am getting the following crash when I present a MFMailComposeViewController
:
2013-11-08 11:04:05.963 <redacted>[7108:1603] *** Assertion failure in NSDictionary *_UIRecordArgumentOfInvocationAtIndex(NSInvocation *, NSUInteger, BOOL)(), /SourceCache/UIKit/UIKit-2380.17/UIAppearance.m:1118
2013-11-08 11:04:06.032 <redacted>[7108:1603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unknown key, "NSColor" in title text attributes dictionary'
我已将其跟踪到AppDelegate中的以下外观设置 application:didFinishLaunchingWithOptions:
method:
I've tracked it down to the following appearance setting in my AppDelegate's application:didFinishLaunchingWithOptions:
method:
[[UINavigationBar appearance] setTitleTextAttributes:
@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
评论该线路确实有效,但是遗留了应用程序的其余部分,所以我试着专门设置titleTextAttributes为 MFMailComposeViewController的空字典
:
Commenting that line out does the trick, but ruins the rest of the app, so I tried specifically setting the titleTextAttributes to an empty dictionary for the MFMailComposeViewController
:
尝试#1
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:@{ }];
导致同样的崩溃。并且
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:nil];
也导致同样的崩溃。
尝试#2
我注意到 MFMailComposeViewController
是 UINavigationController
,因此全局外观设置可能已本地化为UIVavigationController内的 UIVavigationController 。我整理了一些代码来确定MFMailComposeViewController中的视图控制器:
I noticed that MFMailComposeViewController
is a UINavigationController
, so maybe the global appearance settings are localized to UIViewControllers inside a UINavigationController. I put together some code to figure out what view controllers are inside the MFMailComposeViewController:
for (UIViewController *viewController in mailViewController.viewControllers) {
NSLog(@"%@", NSStringFromClass([viewController class]));
}
导致输出结果:
2013-11-08 11:04:05.936 <redacted>[7108:907] MFMailComposeInternalViewController
所以我尝试了(尽管依靠Apple的私人视图控制器是不好的做法):
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:@{ }];
和
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:nil];
但这仍然导致同样的崩溃!
But that still results in the same crash!
尝试#3
// right before instantiating the MFMailComposeViewController
[[UINavigationBar appearance] setTitleTextAttributes:@{ }];
和
[[UINavigationBar appearance] setTitleTextAttributes:nil];
然后在的完成块中恢复全局外观属性dismissViewController:animated:完成:
然而,这种方法也不起作用。有没有人知道如何在全局 UINavigationBar
外观上设置titleTextAttributes而不会崩溃MFMailComposeViewController?
However, this approach didn't work either. Does anyone know how to set titleTextAttributes on the global UINavigationBar
appearance without crashing MFMailComposeViewController?
推荐答案
尝试使用 UITextAttributeTextColor
而不是 NSForegroundColorAttributeName
。
这篇关于MFMailComposeViewController由于iOS6上的全局外观属性而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!