したがって、ユーザーが画面に沿って指をパンすると、青い背景色を の属性付きテキストに動的に設定しようとしていますが、次のエラーメッセージが表示UILabel
される理由を一生理解できません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)
}
}