0

First I would like to thank everyone who attempts to help me with my problem, I am new to iOS development, specifically objective-c, so I apologize if my question is extremely obvious.

I am making an app that loads some new data (parsed from a website but it is NOT a UIWebView) into the same current view every time the user changes a selection on the picker view (UIPickerView). The method that inserts this new data into the current view is called -(IBAction) getNewData: (id) sender.

getNewData is called every time the user makes a new selection with the picker. This is how it is called within the picker method and the picker as well as everything else works fine.

- (void)pickerView:(UIPickerView*)pickerView 
      didSelectRow:(NSInteger)row 
       inComponent:(NSInteger)component
{
    NSString *choosen;
    choosen = [currentLottoNames objectAtIndex:row];    
    [self getNewData:choosen];
}

I would like to implement an activity indicator (spinner) for the loading time in-between the time the user makes/changes his selection on the scroller to the time the actual data shows up in the view after the user has made his selection on the scroller. How would I go about implementing this?

Thank you.

WrightsCS
  • 50,551
  • 22
  • 134
  • 186
Teddy13
  • 3,824
  • 11
  • 42
  • 69

1 Answers1

2

To show the user that you are accessing information via apples built in status bar you use

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

If you would like to display like a pop up message you need to declare in the header a

 UIAlertView *load_message;

and then when you would like to show the load_message use

load_message = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [load_message show];
    UIActivityIndicatorView *active = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    active.center = CGPointMake(load_message.bounds.size.width / 2, load_message.bounds.size.height - 40);
    [active startAnimating];
    [load_message addSubview:active];

and that will show a pop up displayed to the user that you are loading something. This is for locking up the screen showing the user that you are getting some information.

Tony
  • 4,609
  • 2
  • 22
  • 32
  • Okay I figured out where to put it but unfortunately it leads me back to my original problem. The box is a very nice touch though. So the problem is the loading indicator is coming up when the data is already loaded opposed to immediately when the user chooses a different value with the picker. When a user picks a different value on the picker, there is about a 3 second delay and then the content shows up. In these approx 3 seconds I would like the loding to come up then and not at the same time when the data is actually loaded. Thanks – Teddy13 Sep 29 '11 at 02:33
  • Ummm. Are you showing the load_message in the pickerDidChange method? Also I will be on the iPhone Developer chat for another 20 minutes if you are on :) – Tony Sep 29 '11 at 03:15
  • Sorry Tony I was not able to go on.:( What is this pickerDidChange method? I cant seem to find it anywhere, even in the documentation with uipickerview. I feel if this method exists then it is exactly what I may need unless you are referring to the method - (void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component? Thanks again! – Teddy13 Sep 29 '11 at 06:58
  • Hrmm you are correct. I must be thinking of the UISlider. So my only suggestion then is to add a Gesture recognizer onto the view and listen for the touches ended method so you know that they changed it or maybe the touchesMoved or began. That would add a little bit more flexibility umm. I am not a hundred percent sure what you are looking to do though. Could you maybe rephrase your comment? Here is the gesture recognizer tut http://stackoverflow.com/questions/1049889/how-to-intercept-touches-events-on-a-mkmapview-or-uiwebview-objects – Tony Sep 29 '11 at 18:08