0

I am trying to display a loading indicator while I am waiting for a method in another class to return a value. The other class will use NSData to get data from a URL (for server login purposes).

I just want to know how I can stop my code in the main function to stop executing while i wait for the method in the other class to return a value. The main issue i am experiencing is that the indicator disappears because the code is continuing to run before I get a value.

My code is:

[self.view addSubview:loadingView];
loggedIn = [classB login:username password:password];
// More code

[loadingView removeFromSuperview];

I just want to know how i will be able to get around the indicator not being displayer. It will be displayed if i remove the following line:

[loadingView removeFromSuperview];
Awais Hussain
  • 2,400
  • 2
  • 12
  • 11
  • 6
    Stop thinking that way. You never, never, _never_ "stop your code" or "wait". _Communicate_ between parts of your code. Use delayed performance, if needed, to give the interface an opportunity to update. – matt Jan 01 '15 at 14:04
  • See also [How to wait for an asynchronous method to be over?](http://stackoverflow.com/q/6333133) – jscs Jan 01 '15 at 19:12

1 Answers1

1

Send a notification when the process is finished. Add the controller with the loadingView as observer for that notification. Remove the loadingView when the controller receives the notification.

Edit: Added links to documentation.

dasdom
  • 13,975
  • 2
  • 47
  • 58