有没有人知道如何使用UISearchBar搜索MKMapView上的注释?

时间:2011-03-31 16:23:41

标签: xcode uitableview annotations mkmapview uisearchbar

我搜索了几个小时,但我找不到任何东西

也有人能告诉我他们是否知道如何将分组uiTableView中的单元格链接到某个DetailView并将不同的单元格链接到另一个DetailView?

2 个答案:

答案 0 :(得分:1)

对于地图,我会在哪里放置搜索代码,如果这是我的注释。

- (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];

对于UITableView Grouped,如果我的代码看起来像这样,我将在何处以及如何使用该代码:

- (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";
}

答案 1 :(得分:0)

搜索注释 -

这取决于你想要如何搜索注释,如果你想按标题搜索它,那么首先使用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 -

如果你想点击单元格链接,那么你可以在

中进行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

对于组表首先检查indexPath.section,然后检查indexPath.row。