Note that there are some explanatory texts on larger screens.

plurals
  1. POActivity indicator as annotation accessory
    text
    copied!<p>I have a mapView with annotations which they have a button as right accessory view. If you press the button as soon as the annotation details appear then details appear to be empty because there was not enough time to download the required information. What I am seeking is to show an activity indicator as long as there that info is downloading. Here is what I have until now: </p> <pre><code>-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation{ popButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)]; [popButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside]; activityI = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 31, 31)]; [activityI startAnimating]; [popButton addSubview:activityI]; [NSThread detachNewThreadSelector:@selector(threadInfo:) toTarget:self withObject:annotation]; . . . annView.rightCalloutAccessoryView = popButton; } -(void) threadInfo: (MKAnnotationView*) info{ while ([activityI isAnimating]) { if (ok ==0) { } else{ NSLog(@"ok = %i",ok); popButton = (UIButton*) info.rightCalloutAccessoryView; &lt;--error* popButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; [activityI removeFromSuperview]; [activityI stopAnimating]; ok=0; } } } </code></pre> <p>where "ok" = integer where 1 = when downloading process completes successfully</p> <p>where error = Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-["annotation class name" rightCalloutAccessoryView]: unrecognized selector sent to instance 0x17e7fc60'</p> <p>even when I comment out the button the activityI still animates without crashes..</p> <p>Updated: (everything commented out has been tested and not working -not necessarily at the same time. Anything that is not commented was my last try)...</p> <pre><code>-(void) threadInfo: (MKAnnotationView*) annView{ UIButton* popButtons = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)]; act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 31, 31)]; [act setColor:[UIColor greenColor]]; [act startAnimating]; [popButtons addSubview:act]; while ([act isAnimating]) { if (ok ==0) { NSLog(@"ok = %i",ok); } else{ NSLog(@"ok = %i",ok); // popButton = (UIButton*) annView.rightCalloutAccessoryView; //UIButton* popButtons = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)]; popButtons = [UIButton buttonWithType:UIButtonTypeInfoLight]; // UIActivityIndicatorView *currentActivityIndicator = (UIActivityIndicatorView *)[popButton viewWithTag:15]; //currentActivityIndicator.hidden = YES; //[popButtons addSubview:[(UIActivityIndicatorView*) [popButton viewWithTag:15]]]; // [(UIActivityIndicatorView *) [popButton viewWithTag:15] stopAnimating]; // [(UIActivityIndicatorView *) [popButton viewWithTag:15] removeFromSuperview]; annView.rightCalloutAccessoryView = popButtons; //[popButton addSubview:popButtons]; // NSLog(@"view = %@",[popButton viewWithTag:15]); //[act stopAnimating]; // [currentActivityIndicator stopAnimating]; // [currentActivityIndicator removeFromSuperview]; // popButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; //ok=0; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload