1

I am trying to implement a simple spinner while my app seeks data from the Internet. My data grab is working fine, but it sometimes takes a while, so I'd like to use a UIActivityIndicatorView to let the user know that the app hasn't crashed. But it's currently not working. I've gleaned as much as I can from these forums, and others, but for some reason it's not working. Again, I feel like this solution is probably very simple. Here's what I'm doing:

I declare the spinner as a property in the .h file:

 @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

I have also dragged a spinner object onto the viewcontroller using storyboard, and created a connection to the property using CTRL-drag.

The button that triggers the URL request (and consequent loading & parsing of data) actually triggers a segue, so I figure using the

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

function is as good a place as any to get things started. I don't have a specific function attached to the button apart from the prepareforsegue function. (Maybe this is an issue? does it need to have an IBAction associated?...)

Anyway, that function triggers this:

 [self GoAheadAndGetData];

which, in turn, begins like so:

 - (void)GoAheadAndGetData {

[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
  ....... etc

So that function looks like this:

 - (void) threadStartAnimating:(id)data 
 {
    [activityIndicator startAnimating];
 }

And finally, at the end of the GoAheadAndGetData function, I have placed the stop animating call, like so:

 [activityIndicator stopAnimating];

Is that clear? Please let me know if anyone needs more info - I have tried to strip it down to basics, so I don't have to post a ton of code here...

Thank you in advance - I'd really appreciate any help I could get. I don't quite know why it's not working at this point.

pereirap
  • 59
  • 1
  • 12
  • There are 2 different views, correct? – blake305 Apr 13 '12 at 17:00
  • So if you are segueing then you are switching to a new view right? How is the indicator going to show up if you segue away from the view that has it as a property? Also, can you confirm your threadStartAnimating function is getting called? – Justin Paulson Apr 13 '12 at 17:02
  • the PrepareForSegue function runs in the first viewController, in order to prepare for the segue into the new controller, and it runs and finishes before the new one loads. That is the nature of that function - the transition won't happen until after that function runs. As for the startAnimating function, yes - I just NSLogged it, and it is being executed. – pereirap Apr 13 '12 at 17:58
  • 1
    OK, this was probably the dumbest of all mistakes. It's like setting the alarm clock for PM instead of AM: It was a grey indicator on top of a black background, and I was simply unable to see it. I changed the alpha on the background image, and there it was, working as expected. I knew it would be a stupid mistake. Sorry for the wasted time folks, and thank you to those who took time out to respond. – pereirap Apr 13 '12 at 18:32

0 Answers0