Add / reload mapview annotations without blocking the main thread

I can fully upload my annotation map view for the first time. However, if I try to reload the card by pressing the button (after it has already been loaded), the user must wait for the process to complete. This problem arose due to the fact that upon rebooting, new annotations do not appear until the map display is moved significantly when viewForAnnotation is triggered. I saw two other questions similar to my solutions using performSelectorInBackground and executeSelectorOnMainThread . The first one did not work for me :( and the last thing I do not want to do (although this is the only option that works), since I want the user to be able to interact with the map, and download annotations without blocking the main stream. M it is known that such Animations are best done on the main thread, so question 1. Is there no other way to do this than wait for the user to reboot the card? 2. Suggestions on the best way to do this? Thanks in advance.

+4
source share
1 answer

You can use the send queue block to achieve this here is the syntax
You can create your own private queue like this

dispatch_queue_t queue = dispatch_queue_create("com.MyApp.AppTask",NULL); dispatch_queue_t main = dispatch_get_main_queue(); dispatch_async(queue, ^{ //do the fetching of data here(Don't do any UI Updates) dispatch_async(main, ^{ // Do the UI Update here. }); }); 

Apple called it recursive decomposition.
In this bit of code, the calculation is uploaded to the background thread using dispatch_async() and
then dispatch_async() return to the main queue, which will schedule our block to run with the updated data that we calculated in the background thread.

+4
source

Source: https://habr.com/ru/post/1395171/


All Articles