objective-c - WebTry线程锁

标签 objective-c ios multithreading

我正在使用网络服务创建聊天应用程序。在这里,我将调用 Web 服务,在收到消息后,我必须在表格 View 中显示它们,而且我发送的任何内容也必须显示在表格 View 中。为此,我将 UIText 字段放在(上侧)表格 View 上方,无论我键入什么并按下发送按钮消息都会显示在表格中,并且每 30 秒后我调用获取消息服务(为此我使用了线程计时器)并且在收到来自服务器的消息后重新加载数据调用所有数据显示在表格 View 中当键盘不可见时这一切正常但是当键盘出现并等待服务器响应时重新加载数据我的应用程序崩溃并给出以下错误消息。

void _WebThreadLockFromAnyThread(bool), 0xc849490: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.
bool _WebTryThreadLock(bool), 0xc849490: 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.

最佳答案

我的问题是解决我试图通过辅助线程在 TableView 中重新加载数据。

这就是我所做的

 [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:NO]; And My problem is solved 

关于objective-c - WebTry线程锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7161361/

相关文章:

objective-c - 使用 NSUserDefaults 错误保存隐藏按钮状态

objective-c - 如何在 Interface Builder 中更改 UIButton 的背景图像并保留其形状?

ios - 在 iOS 设备上测试时 Unity 游戏滞后

Java:多线程映射:实现比较如何?

java - 使用 ConcurrentHashMap 缓存

ios - 如何在 iOS 中为 NSThread 获取 "parent"线程?

ios - 如何在没有 xib 文件的情况下使用 uiviewcontroller

java - iOS 和 Android 中的 PBEWithMD5AndDES

ios - 在 openstreetmap 多边形中间显示标记(iOS)

iphone - 在应用程序内部使用 SQLite 数据库的最佳方式