2012-08-07 114 views
0

我有一個tableview,每行都有名字,每個標題都有不同的圖像。我需要將這些標題傳遞到mapview,因爲註釋包含作爲註釋標題的標題名稱。如何顯示從表視圖到地圖視圖的註釋?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

UITableViewCell *cell = nil; 
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier"; 
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier]; 
} 

AddressInfo *addressInfo = [addressList objectAtIndex:indexPath.row]; 



NSString *str=[NSString stringWithFormat:@"%@",addressInfo.category]; 
NSString *[email protected]"0"; 
if ([str isEqualToString:str2]) { 
    UIImage *image1=[UIImage imageNamed:@"greyDot.png"]; 
    cell.imageView.image=image1; 
} 
NSString *[email protected]"10"; 
if ([str isEqualToString:str3]) { 
    UIImage *image2=[UIImage imageNamed:@"blackDot.png"]; 
    cell.imageView.image=image2; 
} 
NSString *[email protected]"20"; 
if ([str isEqualToString:str4]) { 
    UIImage *image3=[UIImage imageNamed:@"greendot.png"]; 
    cell.imageView.image=image3; 
} 

NSString *[email protected]"30"; 
if ([str isEqualToString:str5]) { 
    UIImage *image4=[UIImage imageNamed:@"blueDot.png"]; 
    cell.imageView.image=image4; 
} 

NSString *[email protected]"1"; 
if ([str isEqualToString:str6]) { 
    UIImage *image5=[UIImage imageNamed:@"0Dot.png"]; 
    cell.imageView.image=image5; 
} 

cell.textLabel.text = addressInfo.name; 
return cell; 


} 

但在我的MapView我沒有得到確切的圖像標註爲表視圖,我得到隨機圖像從表視圖註解,但標題名稱顯示爲我想要一樣。

這裏是我的MapView代碼:

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: 
(id <MKAnnotation>)annotation { 
    pinView = nil; 
if(annotation != mapview.userLocation) 
{ 

    static NSString *defaultPinID = @"defaultPinID"; 
    pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if (pinView == nil) pinView = [[[MKAnnotationView alloc] 
             initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; 


    AddressInfo *address = [addressArray objectAtIndex:x]; 
NSString *dotstr=[NSString stringWithFormat:@"%@",address.category]; 
    NSString *[email protected]"0"; 
    if([dotstr isEqualToString:dotstr1]) 
    { 
     NSLog(@"string 0 is %@",dotstr1); 
     pinView.image=[UIImage imageNamed:@"greyDot.png"]; 
     NSLog(@"coming here 0"); 
    } 
    NSString *[email protected]"10"; 
    if([dotstr isEqualToString:dotstr2]) 
    { 
     NSLog(@"string 10 is %@",dotstr2); 
     pinView.image=[UIImage imageNamed:@"blackDot.png"]; 
     NSLog(@"coming here 10"); 
    } 
    NSString *[email protected]"20"; 
    if([dotstr isEqualToString:dotstr3]) 
    { 
     NSLog(@"string 20 is %@",dotstr3); 
     pinView.image=[UIImage imageNamed:@"greendot.png"]; 
     NSLog(@"coming here 20"); 
    } 

    NSString *[email protected]"30"; 
    if([dotstr isEqualToString:dotstr4]) 
    { 
     NSLog(@"string 30 is %@",dotstr4); 
     pinView.image=[UIImage imageNamed:@"blueDot.png"]; 
     NSLog(@"coming here 30"); 
    } 
    NSString *[email protected]"1"; 
    if([dotstr isEqualToString:dotstr5]) 
    { 
     NSLog(@"string defau is %@",dotstr5); 
     pinView.image=[UIImage imageNamed:@"greyDot.png"]; 
     NSLog(@"coming here default"); 
    } 







    pinView.canShowCallout = YES; 

    infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    infoButton.tag=k; 
    [infoButton addTarget:self action:@selector(pinLabelClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    pinView.rightCalloutAccessoryView = infoButton; 
    x++; 


} 
else { 
    [mapview.userLocation setTitle:@"I am here"]; 
} 

return pinView; 


} 

在第一屏幕第一行包含每一行我試圖表現出同樣的地圖視圖,但在我的地圖查看藍色註釋顯示左側藍色圖像灰色圖片標題。 沒有人有任何想法如何做到這一點。任何教程或示例代碼?

+0

不要在委託方法中使用伊娃計數器。不要使用按鈕標籤。請參閱http://stackoverflow.com/a/11834582/467105 – Anna 2012-08-07 12:53:15

回答