因此,当用户在屏幕上平移手指时,我尝试为 aUILabel
的属性文本动态设置蓝色背景色,但我终其一生都无法弄清楚为什么我会收到NSRangeException
以下错误消息:Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds
有时。
这是我的代码:
var afterContext = ""
if textDocumentProxy.documentContextAfterInput != nil {
afterContext = textDocumentProxy.documentContextAfterInput!
} else {
afterContext = ""
}
if beforeContext != nil {
if initialContext == nil {
myRange = NSRange(location: 0, length:afterContext.characters.count)
let attrString = NSMutableAttributedString(string: selectedTextView.text!)
attrString.addAttribute(NSBackgroundColorAttributeName, value: UIColor(red: 20/255, green: 111/255, blue: 225/255, alpha: 1), range: myRange)
}
}