ios - show spinner and remove it in the same block -
in method can take several seconds have:
uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc]initwithframe:cgrectmake(135,140,50,50)]; spinner.color = [uicolor bluecolor]; [spinner startanimating]; [_mapviewcontroller.view addsubview:spinner]; // lots of code [spinner removefromsuperview];
the spinner doesn't show up. since screen doesn't update @ time. how can around problem?
use gcd:
uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc]initwithframe:cgrectmake(135,140,50,50)]; spinner.color = [uicolor bluecolor]; [spinner startanimating]; [_mapviewcontroller.view addsubview:spinner]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ // lots of code run in background dispatch_async(dispatch_get_main_queue(), ^{ // stop , remove spinner on main thread when done [spinner removefromsuperview]; }); });
Comments
Post a Comment