zoukankan      html  css  js  c++  java
  • NSMutableAttributing相关 ios7升级ios8出现的问题

    项目在ios7上没有问题,但是升级ios8以后,出现了不少问题,其中一个追踪到就是在NSMutableAttributing的使用上出现的问题。

    项目中有个功能是:有一串字符串,对指定位置的字符设置不同的颜色,就是使用NSMutableAttributedString来实现的:

    NSMutableAttributedString *attibuttionStr = [[NSMutableAttributedString alloc] initWithString:str];

    [attibuttionStr addAttribute:(NSString *)NSForegroundColorAttributeName

                               value:(id)firstColor.CGColor

                               range:oneRange];

    在ios7上这样是能正常实现的

    但是ios8上除了问题,程序崩溃,提示“

    2014-09-23 13:30:50.224 RecordForStudy[17993:413448] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType set]: unrecognized selector sent to instance 0x7fcbcba07090'

    最终找出,

    在ios8上用value:(id)firstColor.CGColor就会报错,

    改成value:(id)firstColor就好了。

    [attibuttionStr addAttribute:(NSString *)NSForegroundColorAttributeName

                               value:(id)firstColor

                               range:oneRange];

    这样就好了。

    总结:在ios7以及之前,value的值写

    1、(id)firstColor.CGColor

    或者直接写

    2、(id)firstColor

    都是没问题的,

    但是在ios8上只能写成2、(id)firstColor这种样式才是正确的

  • 相关阅读:
    【游戏】有趣的小游戏合集
    “卖我一枝笔”:如何史蒂夫·乔布斯将这一经典问题作出回应?
    Codeforces548D:Mike and Feet(单调栈)
    一对多自身关联双向映射
    MVC action返回partialView前台html 拼接
    c#关于委托和事件
    中国A股市场缘何遭遇9连跌?
    vb.net 字符串的操作 应用
    BitNami Redmine Stack
    窥探内存管理
  • 原文地址:https://www.cnblogs.com/guatiantian/p/3988184.html
Copyright © 2011-2022 走看看