“PostMessage”从工作线程发送消息到主GUI线程

时间:2012-04-27 04:17:02

标签: iphone objective-c message-queue

我创建了一个线程,现在我想从线程向主GUI线程发送消息(做特定事件),这样GUI线程就可以执行我的message.can任何一个告诉我如何做到这一点在iphone(Objective C)

2 个答案:

答案 0 :(得分:3)

  //This will call selected method on main thread and you can do what ever you want to do in your selected method.

[self performSelectorOnMainThread:@selector(yourmethod) withObject:yourobject waitUntilDone:NO];

希望,这会对你有帮助..

答案 1 :(得分:1)

您可以使用GCD和阻止

dispatch_async(dispatch_get_main_queue(), ^{
    // UI code to run on main thread
});