Best way to performselectoronmainthread in objective c?

ⅰ亾dé卋堺 提交于 2019-12-03 07:20:00

Well, you're already using dispatch_async. Then you should just use

     dispatch_async(dispatch_get_main_queue(),^ { ... } );

from inside your background thread to perform things on the main thread. For example,

     if ([self testServerMethod])
        {
            dispatch_async(dispatch_get_main_queue(),^ {
               [self showMessageBoxWithString: @"Server is working!"];
               [self threadedUIActivityRemover:nil];
            } );
        }else ...

It doesn't have any constraint on the number of arguments for the methods you call.

justin

Pass a collection, such as a dictionary of unarchived objects.

justin

You can also use an NSInvocation.

since you are passing instance variables, another option would be to pass self and make self thread safe.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!