【问题标题】:Adding UITextView to custom tableViewCell = Crash将 UITextView 添加到自定义 tableViewCell = Crash
【发布时间】:2012-04-25 05:46:39
【问题描述】:

我有一个自定义表格视图单元格,其中包含一些对象 UIImageView、UILabel 和一个 UITextView。除了 UITextView 之外的所有对象都可以正常工作,但是当我尝试更改 textView 上的文本时:

 myTextView.text = @"Some string"; 

应用程序因此错误而崩溃:

Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

非常感谢任何建议。 谢谢

【问题讨论】:

  • 您似乎正在尝试从辅助线程更新文本,是这样吗?你能再添加一些代码吗?
  • 使用 performSelectorOnMainThread(NSObject 方法)来更新你的 UITextView

标签: iphone objective-c xcode


【解决方案1】:

该错误听起来像是您正在从不在主线程上执行的代码块中设置文本属性。检查以确保您拥有的任何修改 UIKit 对象的代码都在主线程上执行此操作。下面的例子:

dispatch_async(dispatch_get_main_queue(), ^{
            // Set text here
            myTextView.text = @"Some string"; 
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    相关资源
    最近更新 更多