iOS 7 Only App在启动时崩溃

Hac*_*ord 22 crash ios ios7

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

-[UICachedDeviceWhiteColor shadowColor]: unrecognized selector sent to instance 0x156f22f0
Run Code Online (Sandbox Code Playgroud)

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

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

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

[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激

ban*_*isa 85

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

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

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

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

你需要做的是有一个属性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];
Run Code Online (Sandbox Code Playgroud)