1

HI all, if i've somthing like this:

my code....
// active indicator activity
[otherClass method]; // method that takes 5-6 seconds
// disable indicator activity
my code...

When the long method is called, in my class code is blocked right?

If i active an indicator activity before call the method, it will be animating while "method" is executing?

Thanks.

1
  • 1
    I'm not sure what your question is? Are you asking if you enable an animation will it keep playing? If so then it would depend on how your app works. Commented May 13, 2011 at 7:07

3 Answers 3

1

As iceydee mentions, the UI elements (like your activity indicator) run on the main thread. If you load a big file, download something or any other thing that takes time, you must execute that on other thread if you want to animate UI elements. You can use Grand Central Dispatch, performSelectorInBackGround or other techniques (not recommendable). I would make:

my code....
// active indicator activity
[otherClass performSelectorInBackground:@selector(method) withObject:nil]; // method that takes 5-6 seconds
my code...

Then in otherClass's method, stop the activity indicator on the main thread:

[activityIndicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
Sign up to request clarification or add additional context in comments.

Comments

0

You should avoid blocking the main thread for that long, consider breaking the method into two - running [otherClass method] in a separate thread. The main thread is used for UI updates, unsure if the indicator will be able to operate with main thread blocked, I think not.

Comments

0

Yes, it will be blocked unless you run your long method in another thread.

To do this use a technique like this. see performSelectorInBackground and performSelectorOnMainThread.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.