最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - UITextField crash on setSelectedTextRange: - Stack Overflow

programmeradmin2浏览0评论

Recently I got a few crashes on UITextField:

Fatal Exception: NSInvalidArgumentException -[<_UIObscurableTextContentStorage: 0x30016cd20> offsetFromLocation:toLocation:] received invalid locations 0 (null)

But I'm not able to reproduce this crash on my side. Here's my code snippet:

dispatch_async(dispatch_get_main_queue(), ^{
    UITextPosition *newPosition = textField.endOfDocument;
    textField.selectedTextRange = [textField textRangeFromPosition:newPosition toPosition:newPosition];  // crash at this line
});

I'm guessing either the textField.endOfDocument or UITextRange variable returned from textRangeFromPosition:toPosition: could be nil, but I have tried hardcoding these variables to nil and still cannot reproduce this crash. Besides, Apple Document claims that textField.endOfDocument is not an optional value.

Therefore, does anyone have any clue about the root cause for this crash?

发布评论

评论列表(0)

  1. 暂无评论