当我改变iphone的语言导致崩溃?

时间:2017-12-19 12:16:28

标签: ios iphone swift localization nsmutablestring

   let initialStr = "To see information for today, please"

        let tempFontSize = UIUtils.getFontForApproprieteField(.subHeadline).font.pointSize

        let tealDict = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: tempFontSize), NSAttributedStringKey.foregroundColor: UIColor.LTColor()]
        let linkAttributes = [NSAttributedStringKey.foregroundColor: UIColor.LTColor(), NSAttributedStringKey.underlineStyle: NSNumber(value: false as Bool)]
        errorLbl?.linkAttributes = linkAttributes
        errorLbl?.delegate = self

        let attributedString = NSMutableAttributedString(string: AppMessage.emptyWidget, attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: tempFontSize)])
        attributedString.addAttributes(tealDict, range: NSMakeRange(initialStr.length+1,3))
        errorLbl?.attributedText = attributedString

        let rangeT : NSRange = (AppMessage.emptyWidget as NSString).range(of: " add")
        errorLbl?.addLink(to: URL(string: "https://www.google.co.in/")!, with: rangeT)

我想将 之后的添加作为超链接。它在所有设备上工作,除非我们更改语言时此行会导致崩溃。

当我改变iphone语言这一行导致崩溃?

languageChange: - 英语 - >印地语

崩溃:

  

由于未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray objectAtIndex:effectiveRange :: out of bounds'

1 个答案:

答案 0 :(得分:0)

AppMessage.emptyWidget是一个本地化的字符串,但该键在localised.string中没有相应的值,这就是为什么范围问题存在。 添加了key和app的值。