如何显示从表视图到地图视图的注释?
问题描述:
我有一个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;
}
在第一屏幕第一行包含每一行我试图表现出同样的地图视图,但在我的地图查看蓝色注释显示左侧蓝色图像灰色图片标题。 没有人有任何想法如何做到这一点。任何教程或示例代码?
不要在委托方法中使用伊娃计数器。不要使用按钮标签。请参阅http://stackoverflow.com/a/11834582/467105 – Anna 2012-08-07 12:53:15