iOS 7 Only App在启动时崩溃

问题描述 投票:22回答:2

我最近将我的xcode项目改为iOS 7,而不是支持iOS 5.在应用程序启动后立即进行此更改后,我在控制台中收到此消息。

-[UICachedDeviceWhiteColor shadowColor]: unrecognized selector sent to instance 0x156f22f0

我不确定是什么原因造成的。但使用调试器似乎我的应用程序委托在第一行代码崩溃。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window.rootViewController = self.tabBarController; //this line is where it crashes

[self.window makeKeyAndVisible];

任何帮助,将不胜感激

ios crash ios7
2个回答
85
投票

您可能做了我所做的事情,过度切割并替换了UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset的编译器警告。所以你的代码看起来像这样:

NSDictionary *titleAttributes = @{UITextAttributeTextColor: [UIColor whiteColor],
                                  UITextAttributeTextShadowColor: [UIColor blackColor],
                                  UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
                                  UITextAttributeFont: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

并用NSShadowAttributeName替换它们,最后得到一些像这样的代码:

NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                  NSShadowAttributeName: [UIColor blackColor],
                                  NSShadowAttributeName: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
                                  NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

你需要做的是有一个属性NSShadowAttributeName,并创建一个包含阴影颜色和阴影偏移的NSShadow实例。

NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                  NSShadowAttributeName: shadow,
                                  NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

0
投票

由于为归因String提供了不同的NSAttributedString.key和值,因此出现此问题。

错误:让prefixAttribute = [NSForegroundColorAttributeName:UIFont(名称:“HelveticaNeue-Light”,大小:11.0),NSFontAttributeName:UIColor.darkGray]

解决:let prefixAttribute = [NSFontAttributeName:UIFont(名称:“HelveticaNeue-Light”,大小:11.0),NSForegroundColorAttributeName:UIColor.darkGray]

我已将colorarrtibute与字体互换,反之亦然

© www.soinside.com 2019 - 2024. All rights reserved.