【问题标题】:Assertion failure in -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-3318/UIColor.m-[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-3318/UIColor.m 中的断言失败
【发布时间】:2015-01-30 10:44:31
【问题描述】:
- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.

  UIColor *navBarColor =
  [UIColor colorWithPatternImage:[UIImage imageNamed:@"SandPattern.jpg"]];

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1 {
    [[UINavigationBar appearance] setTintColor:navBarColor];
    }
        else {
    [[UINavigationBar appearance] setBarTintColor:navBarColor];
        }
        // various functions....
        return YES;
}

应用崩溃并抛出以下错误。

*** -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-3318/UIColor.m:1448 中的断言失败

*** -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-3318/UIColor.m:1448 中的断言失败

libc++abi.dylib: terminate_handler 意外抛出异常

【问题讨论】:

    标签: ios iphone xcode


    【解决方案1】:

    我移动了代码以将导航栏更新为一个函数,并在 AppDelegate.m 中的其他函数之后调用它,它工作正常。仍在寻找崩溃背后的确切逻辑。

    -(void)updateUI{
        UIColor *navBarColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"SandPattern.jpg"]];
        //    [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
            [[UINavigationBar appearance] setTintColor:navBarColor ];
        }
        else {
            [[UINavigationBar appearance] setBarTintColor: navBarColor];
        }
    }
    

    这样的最终代码

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
                // Override point for customization after application launch.
    
             // various functions....
               [self updateUI];
                return YES; 
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2012-02-01
      • 1970-01-01
      • 2021-06-28
      • 2013-10-02
      • 1970-01-01
      相关资源
      最近更新 更多