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这种样式才是正确的

  • 相关阅读:
    解决MyBatis的Mapper XML错误,系统起不来,也不报错问题
    tomcat启动卡在“INFO com.alibaba.druid.pool.DruidDataSource
    加速github访问速度
    LAN、WAN和WLAN的区别
    面试记录一
    C++纯虚函数(接口类)的使用
    CentOS 安装 Docker CE
    通过 plsql 连接远程 Oracle
    Yum 软件仓库配置
    qW3xT.2,解决挖矿病毒
  • 原文地址:https://www.cnblogs.com/guatiantian/p/3988184.html
Copyright © 2011-2022 走看看