objective c - How should this code be changed to work correctly? -
i downloaded code http://github.com/matej/mbprogresshud show progress meter when doing something.
this code makes progress meter pop up.
[hud showwhileexecuting:@selector(mytask) ontarget:self withobject:nil animated:yes];
this show progress meter while method mytask running.
the strange thing allow program execution continue below line while mytask running. not behavior want. want progress meter show while mytask running, , after mytask finishes running want program execution continue below line.
this code showwhileexecuting method.
- (void)showwhileexecuting:(sel)method ontarget:(id)target withobject:(id)object animated:(bool)animated { methodforexecution = method; targetforexecution = [target retain]; objectforexecution = [object retain]; // launch execution in new thread taskinprogress = yes; [nsthread detachnewthreadselector:@selector(launchexecution) totarget:self withobject:nil]; // show hud view [self show:animated]; }
in order behavior want, should edit code, or else?
i tried around problem setting bool value before calling method causes program execution stuck in while loop after until bool value changed @ end of mytask. works, reason causes meter show instant @ end, , not throughout it's supposed to. why that?
the method calling running task on new thread.
your while loop method not working because the ui display update done on main thread. while in while loop block main thread.
i suggest move code want run after task completes new method. then, @ end of task, call method. (or alternatively, have send notification, or other signal.)
also, documentation threading , run loops, it's important understand topic.
Comments
Post a Comment