Best way to performselectoronmainthread in objective c?

前端 未结 4 2173
离开以前
离开以前 2021-02-09 05:44

I\'m writing a client-server app to iPhone. And I have a question about threading. When I access my online database from the device, I need to do this on a separate thread to no

4条回答
  •  悲哀的现实
    2021-02-09 06:27

    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.

提交回复
热议问题