Daniel Christmas
Daniel Christmas

Reputation: 27

Does any one know how to search the annotations on MKMapView with UISearchBar?

I've searched for hours and I found Nothing

Also can anyone tell me if they know how to link a cell in grouped uiTableView to a certain DetailView and link a different cell to another DetailView?

Upvotes: 0

Views: 1351

Answers (2)

saadnib
saadnib

Reputation: 11145

search annotation-

It depends on by how you want to sear an annotation, if you want to search it by title then first get all the annotation by using annotation property of MKMapView as -

NSArray *arr = [mapView annotations];

for(int i=0; i<[arr count]; i++)
{ 
     MKAnnotation *ann = [arr objectAtIndex:i];
     if([ann.title isEqualToString:[searchBar text]])
     {
         //do what you want to do after getting a annotation
     }
}

UITableView -

If you want to link on tap on cell then you can do it in

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

for group table first check for indexPath.section and then check for indexPath.row .

Upvotes: 0

Daniel Christmas
Daniel Christmas

Reputation: 27

For the Map, Where would I put the Search Code and at if this is my annotations.

- (void)viewDidLoad {
    [super viewDidLoad];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];


    // Central Alabama Chapter

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region.center.latitude = 33.45606;
    region.center.longitude = -86.83078;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;

    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];

    DisplayMap *ann = [[DisplayMap alloc] init]; 
    ann.title = @"Central Alabama Chapter";
    ann.subtitle = @"721 Hillmoor Lane Homewood, Alabama 35209"; 
    ann.coordinate = region.center; 
    [mapView addAnnotation:ann];


    // Walnut Ridge Fire Department

    MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region1.center.latitude = 36.11493;
    region1.center.longitude = -90.95695;
    region1.span.longitudeDelta = 0.01f;
    region1.span.latitudeDelta = 0.01f;



    DisplayMap *ann1 = [[DisplayMap alloc] init]; 
    ann1.title = @"Walnut Ridge Fire Department";
    ann1.subtitle = @"3217 Highway 67 # B, Walnut Ridge, AR"; 
    ann1.coordinate = region1.center; 
    [mapView addAnnotation:ann1];

For the UITableView Grouped, where and how would i use that code if the code I have Looks like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    //Initialize the array.
    listOfItems = [[NSMutableArray alloc] init];

    NSArray *sectionOneArray = [NSArray arrayWithObjects:@"Mission Statement", @"Become a Member", @"Bible Ministries", @"FCFi on Facebook", @"Chapter Kit (PDF)", @"Corporate Members", @"FDIC Indianapolis", @"9/11/2001", nil];

    NSArray *sectionTwoArray = [NSArray arrayWithObjects:@"About", @"Developer", nil];

    NSArray *websiteArray = [NSArray arrayWithObjects:@"FCFi Website", nil];

    [listOfItems addObject:sectionOneArray];
    [listOfItems addObject:sectionTwoArray];
    [listOfItems addObject:websiteArray];

    //Set the title
    self.navigationItem.title = @"More";
}

Upvotes: 1

Related Questions