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

问题描述 投票:0回答:1
   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)

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

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

languageChange: - 英语 - >印地语

崩溃:

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

ios iphone swift localization nsmutablestring
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.