Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity Indicator when integrated into Searchbar does not display in iPhone SDK

In my iPhone app, I want to add activity indicator on top of a searchbar.

When it is searching it should display activity indicator.

I have added the activity indicator in XIB and created its outlet.

I am making it hide when the searching finishes, but Activity Indicator does not display.

Problem

I figured out that search function(say A)(where I animate the activity indicator) in turn calls another function(say B) so the main thread is being used in executing the function B. But for activity indicator to animate we require the main thread.

So I tried calling function B using performSelectorInBackGround:withObject method. Now when I click search the activity indicator is shown but the functionality of function B does not execute.

What can be a work-around for this?

like image 787
Parth Bhatt Avatar asked Dec 11 '10 06:12

Parth Bhatt


2 Answers

There is not quite enough in your question to go on, but to start debugging, I would do the following.

  1. Verify that the activity variably is really wired to the UIActivityIndicator you are creating in IB. (I would set a breakpoint on the setHidden: lines and make sure the variable is not null. Or throw an NSAssert(activity,@"Whoops! actity is null"); in there.)

  2. If the variable is indeed set, I would start checking that it is in the right place in the view hierarchy. (I'd try doing a [self.view addSubview:activity] and see that it appears. You might have to replace it somewhere else.)

  3. You might also want to try having it on by default in IB, until you have everything figured out.

Good Luck. Hope this helps.

like image 76
Brad The App Guy Avatar answered Oct 23 '22 16:10

Brad The App Guy


Save yourself the hassle of creating a custom activity indicator and use the standard one that's available for you already - in the top bar. Also, IMO users tend to expect that one to spin when something is happening.

UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES; 

Obviously, set it to NO when your activity is over.

like image 36
gnuchu Avatar answered Oct 23 '22 15:10

gnuchu