code_junkie

Does UIActivityIndicator require manual threading on iPhone

Nov 13th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. - (IBAction)syncOnThreadAction:(id)sender
  2. {
  3. [self willStartJob];
  4.  
  5. id myObject = [MyObjectClass createNewObject];
  6. [self performSelectorInBackground:
  7. @selector(inThreadStartDoJob:)
  8. withObject:myObject
  9. ];
  10. }
  11.  
  12. - (void)inThreadStartDoJob:(id)theJobToDo
  13. {
  14. NSAutoreleasePool * pool;
  15. NSString * status;
  16.  
  17. pool = [[NSAutoreleasePool alloc] init];
  18. assert(pool != nil);
  19.  
  20. status = [theJobToDo countGrainsOfSandOnBeach];
  21.  
  22. [self performSelectorOnMainThread:
  23. @selector(didStopJobWithStatus:)
  24. withObject:status
  25. waitUntilDone:NO
  26. ];
  27.  
  28. [pool drain];
  29. }
  30.  
  31. -(void)submit_Clicked:(id)event
  32. {
  33. [self.spinner startAnimating];
  34. [self performSelector:@selector(displayComposerSheet)
  35. withObject:nil afterDelay:0];
  36. }
  37.  
  38. 1> Have 1 method that starts the spinner (in the background).
  39. 2> Run your long-running code right here.
  40. 3> Have 1 method that ends the spinner.
  41.  
  42. A> Have 1 method that starts the spinner.
  43. B> Have 20 methods (1 for each thing you want to do in the background)
  44. C> Have 1 method that ends the spinner.
Add Comment
Please, Sign In to add comment