UITextView冻结了来自textViewShouldBeginEditing的iPad应用程序。 (无效的字形索引) [英] UITextView freezes iPad app from textViewShouldBeginEditing. (Invalid Glyph Index)

查看:366
本文介绍了UITextView冻结了来自textViewShouldBeginEditing的iPad应用程序。 (无效的字形索引)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在研究这个bug大约一个星期,而对于我的生活,我无法弄清楚发生了什么。

So I've been working on this bug for about a week now, and for the life of me I can't figure out what's happening.

由于机密性问题,我无法发布太多代码,但我会尽力解释所有内容。

Due to confidentiality issues I can't post too much code, but I'll do my best to explain everything.

我们正在通过代码填充UITextField,并且最初将文本显示为灰色。然后用户可以执行以下两种操作之一:

What's happening is that we're populating a UITextField via code, and initially have the text greyed out. The user then can do one of two things:

1)点击一个显示commit的按钮,调用一个方法,执行以下方法,我们将调用 commitData。它执行以下操作:

1) Tap a button which says "commit" and a method is called which does the following method we'll call "commitData". It does the following:


  1. 使用撤消管理器注册提交

  2. 从灰色更改文本黑色

  3. 向我们的应用程序注册文本字段已更新,需要在申请结束时保存

2)点击带有灰色文本的文本字段,然后调用以下默认的apple方法textViewShouldBeginEditing。从这里我们调用我们在选项1中列出的commitData方法,如下所示:

2) Tap on the text field with the greyed out text, which then calls the following default apple method textViewShouldBeginEditing. From here we call our "commitData" method listed from option 1 like so:

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ([[self box] hasGreyedOutText])
        [[self box] commitData];

    [self setActiveTextView:textView];
    return YES;
}

我们遇到的问题是点击按钮提交灰色文本工作得很好,我们没有遇到任何问题。

The issue we're having is that tapping the button to commit the greyed out text works perfectly fine, and we run into no issues.

HOWEVER

当我们点击文本字段时并触发textViewShouldBeginEditing方法,我们的iPad可以冻结并让用户在完成之前等待几分钟。当我的意思是冻结时,我的意思是整个iPad冻结。发生这种情况时,iPad时钟甚至不会更新。

When we tap into the text field and trigger the textViewShouldBeginEditing method, our iPads can freeze up and make the user wait for a couple of minutes before finishing. When I mean freeze, I mean the entire iPad freezes. The iPad clock won't even update while this is happening.

当发生这种情况时,我们会在控制台中收到错误代码:

When this happens, we get an error code in the console which says:

!!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 2147483647

我们可以获取上面的错误代码,以便在关注时显示在我们所有的硬件上上面的步骤,但只能在iPad 2上重现冻结(但准确率为100%)。

We can get the error code above to display from all of our hardware when following the steps above, but can only reproduce the freezing on an iPad 2(with 100% accuracy however).


  • 关于此的说明,我的同事通过诊断发现,当发生此错误时,我们只有大约8MB的可用RAM。我们只在iPad 2上打过这么小的RAM,所以这可能只是巧合。

我觉得这可能与线程有关,我们可能需要在从textViewShouldBeginEditing返回YES后以某种方式调用我们的方法方法,但我不太清楚我应该怎么做。

I have a feeling that this could be related to threading and that we might need to somehow call our method after returning YES from the textViewShouldBeginEditing method, but I'm not quite sure how I should be going about that.

如果有人对如何解决这个问题有任何想法,甚至可能指出我的想法在正确的方向,我将非常感激。我到处都看到了我能想到的,而且我找到的与错误代码相关的解决方案都没有结束。

If anybody has any ideas on how to fix this, or even ideas that could point me in the right direction, I would be incredibly grateful. I've looked everywhere I can possibly think of, and none of the solutions I've found relating to the error code have ended up working.

推荐答案

我无法调试,所以在我的猜测中它可能是由非主线程UI操作引起的。所以,我的建议是确保您的UI代码在mainThread中。试试这个:

I can't debug, so in my guess it may caused by non-main thread UI operation. So, my suggestion is to make sure your UI code is in mainThread. Try this:

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    dispatch_async(dispatch_get_main_queue(), ^{ 
    if ([[self box] hasGreyedOutText])
        [[self box] commitData];
    [self setActiveTextView:textView];
    }
    return YES;
}

这篇关于UITextView冻结了来自textViewShouldBeginEditing的iPad应用程序。 (无效的字形索引)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆