【问题标题】:iOS 7 Only App Crashes at StartupiOS 7 只有应用程序在启动时崩溃
【发布时间】:2013-09-28 21:12:43
【问题描述】:

我最近将我的 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 时会做什么?默认选项卡中有什么?

标签: ios crash ios7


【解决方案1】:

您可能做了我所做的,并且过分热心地删除和替换了 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] 是关于您的编辑的正确语法。
  • 酷哥们.. 谢谢你的回答.. 节省了一个小时... :)
【解决方案2】:

这个问题是由于赋予不同的 NSAttributedString.key 和 value 给属性化的 String。

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

已解决: 让前缀属性 = [ NSFontAttributeName:UIFont(名称:“HelveticaNeue-Light”,大小:11.0), NSForegroundColorAttributeName: UIColor.darkGray]

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

【讨论】:

    猜你喜欢
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多