iOS 7独有的应用程序在启动时崩溃

22

我最近将我的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];

任何帮助都将不胜感激


什么是堆栈跟踪?当选项卡控制器加载其视图/NIB时,它会执行什么操作?默认选项卡中有什么? - Wain
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];

半个小时,就这样了吗?顺便说一下,[NSShadow.alloc init]是关于你的编辑的正确语法。 - bandejapaisa

0

这个问题是由于给NSAttributedString.key和value赋予不同的值而引起的。

错误: let prefixAttribute = [ NSForegroundColorAttributeName: UIFont(name: "HelveticaNeue-Light", size: 11.0), NSFontAttributeName: UIColor.darkGray]

解决: let prefixAttribute = [ NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 11.0), NSForegroundColorAttributeName: UIColor.darkGray]

我已经交换了colorarrtibute和font的位置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接