当我提出 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:
方法中将其追踪到以下外观设置:
[[UINavigationBar appearance] setTitleTextAttributes:
@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
注释掉那条线可以解决问题,但会破坏应用程序的其余部分,因此我尝试专门将 titleTextAttributes 设置为空字典MFMailComposeViewController
:
尝试#1
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:@{ }];
这会导致同样的崩溃。和
[[UINavigationBar appearanceWhenContainedIn:
NSClassFromString(@"MFMailComposeViewController"), nil]
setTitleTextAttributes:nil];
也会导致同样的崩溃。
尝试#2
我注意到这MFMailComposeViewController
是一个UINavigationController
,所以也许全局外观设置被本地化为UINavigationController内的 UIViewControllers。我整理了一些代码来确定 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];
但这仍然会导致同样的崩溃!
尝试#3
// right before instantiating the MFMailComposeViewController
[[UINavigationBar appearance] setTitleTextAttributes:@{ }];
和
[[UINavigationBar appearance] setTitleTextAttributes:nil];
然后在完成块中恢复全局外观属性dismissViewController:animated:completion:
但是,这种方法也不起作用。有谁知道如何在全局UINavigationBar
外观上设置 titleTextAttributes 而不会导致 MFMailComposeViewController 崩溃?