ios7只有在启动时才会崩溃。

时间:2022-12-09 04:02:17

I recently changed my xcode project to be iOS 7 only instead of supporting iOS 5. After making this change as soon as the app starts I get this message in the console.

最近我将xcode项目改为ios7,而不是支持ios5。在应用程序启动之后,我在控制台中得到了这个消息。

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

I'm not sure what is causing this. But using the debugger it seems like my app delegate is crashing at the first line of code.

我不知道是什么引起的。但使用调试器时,我的应用程序委托似乎在第一行代码中崩溃了。

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

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

[self.window makeKeyAndVisible];

Any help would be appreciated

如有任何帮助,我们将不胜感激。

1 个解决方案

#1


85  

You probably did what I did, and overzealously cut and replaced the compiler warnings for UITextAttributeTextShadowColor and UITextAttributeTextShadowOffset. So you had code that looked like this:

您可能已经做了我所做的,并且过度地剪切并替换了UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset的编译器警告。代码是这样的

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

and replaced them both with NSShadowAttributeName, and ended up with some code like this:

然后用NSShadowAttributeName替换它们,最后得到这样的代码:

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

What you need to do is have one attribute NSShadowAttributeName, and create an instance of NSShadow that contains the shadow color and shadow offset.

您需要做的是有一个属性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];

#1


85  

You probably did what I did, and overzealously cut and replaced the compiler warnings for UITextAttributeTextShadowColor and UITextAttributeTextShadowOffset. So you had code that looked like this:

您可能已经做了我所做的,并且过度地剪切并替换了UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset的编译器警告。代码是这样的

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

and replaced them both with NSShadowAttributeName, and ended up with some code like this:

然后用NSShadowAttributeName替换它们,最后得到这样的代码:

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

What you need to do is have one attribute NSShadowAttributeName, and create an instance of NSShadow that contains the shadow color and shadow offset.

您需要做的是有一个属性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];