Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:47:46+00:00 2026-06-13T08:47:46+00:00

Update :Michael got it right. Here is my solution: – (void) connectNextCarOnMainThread:(id)annotation{ [self performSelectorOnMainThread:@selector(connectNextCar:)

  • 0

Update:Michael got it right. Here is my solution:

- (void) connectNextCarOnMainThread:(id)annotation{
    [self performSelectorOnMainThread:@selector(connectNextCar:) withObject:annotation waitUntilDone:YES];
}

- (void) connectNextCar:(id)annotation{
    Pin *pin = (Pin *)annotation;
    MKMapRect zoomRect = MKMapRectNull;
    MKMapPoint annotationPoint = MKMapPointForCoordinate(pin.coordinate);
    MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 3, 3);
    if (MKMapRectIsNull(zoomRect)) {
         zoomRect = pointRect;
    } else {
         zoomRect = MKMapRectUnion(zoomRect, pointRect);
    }
    [mapView setVisibleMapRect:zoomRect animated:YES];
    [mapView selectAnnotation:pin animated:YES];

    NSInteger currentIndex=[self.annotations indexOfObject:annotation];
    if(currentIndex < [self.annotations count]){
        [self performSelector:@selector(connectNextCarOnMainThread:) withObject:[self.annotations objectAtIndex:currentIndex+1] afterDelay:5];
    }
}


I want to achieve a simple feature: center and select one of my annotations every X seconds. But I’m getting some strange behavior in my annotation callouts.

Here is my code:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    if(self.movedToFitPins){
        for(id <MKAnnotation> pin in self.annotations)
            [self.mapView addAnnotation:pin];
        self.movedToFitPins = NO;
        [self performSelectorInBackground:@selector(fakeCarConnections) withObject:nil];
    }
}

- (void) fakeCarConnections {
    for (Pin *annotation in self.annotations)
    {
        [NSThread sleepForTimeInterval : 10.0];
        MKMapRect zoomRect = MKMapRectNull;
        MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
        MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 3, 3);
        if (MKMapRectIsNull(zoomRect)) {
            zoomRect = pointRect;
        } else {
            zoomRect = MKMapRectUnion(zoomRect, pointRect);
        }
        [mapView setVisibleMapRect:zoomRect animated:YES];
        [mapView selectAnnotation:annotation animated:YES];
    }
}

So, what is happening is that I do focus on the Annotation, the callout bubble does open but with no text inside. If i click in the annotation, the callout opens up correctly with the text.
Here is the catch: if I comment the sleepForTimeInterval line, the code works fine, but I only see the last annotation since it passes trough all the others.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:47:47+00:00Added an answer on June 13, 2026 at 8:47 am

    All UI modifications/messages should occur on the main thread. I’d suggest that you modify your looping code so that instead of a sleep it uses performSelectorOnMainThread after a time interval (and each subsequent call calls the next one). That way you won’t block the main thread and will still get the desired effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Final update and fix : The solution here turned out to be a combination
Update the key issue here is an impedance mismatch between the ruby objects and
I'm working on chapter 11 of Michael Hartl's RailsTutorial and I got this error
Here's what I'm trying to do: Update an arbitrary number of rows, changing several
UPDATE: This has been identified as a bug in Chrome. (Thanks @michael-robinson) In Chrome
I'm following Michael Hartl's tutorial here and am trying to create an index of
Update: Is there a way to achieve what I'm trying to do in an
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find
Update: I reported this as a bug to Apple and they fixed it! All
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.