各行に名前があり、タイトルごとに異なる画像を持つ1つのテーブルビューがあります。注釈には注釈のタイトルとしてタイトル名が含まれているため、これらのタイトルを 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 *str2=@"0";
if ([str isEqualToString:str2] ) {
UIImage *image1=[UIImage imageNamed:@"greyDot.png"];
cell.imageView.image=image1;
}
NSString *str3=@"10";
if ([str isEqualToString:str3] ) {
UIImage *image2=[UIImage imageNamed:@"blackDot.png"];
cell.imageView.image=image2;
}
NSString *str4=@"20";
if ([str isEqualToString:str4] ) {
UIImage *image3=[UIImage imageNamed:@"greendot.png"];
cell.imageView.image=image3;
}
NSString *str5=@"30";
if ([str isEqualToString:str5] ) {
UIImage *image4=[UIImage imageNamed:@"blueDot.png"];
cell.imageView.image=image4;
}
NSString *str6=@"1";
if ([str isEqualToString:str6] ) {
UIImage *image5=[UIImage imageNamed:@"0Dot.png"];
cell.imageView.image=image5;
}
cell.textLabel.text = addressInfo.name;
return cell;
}
しかし、私のマップビューでは、テーブル ビューのように正確な画像注釈を取得していません。テーブル ビューから注釈としてランダムな画像を取得していますが、タイトル名は希望どおりに表示されます。
これが私のマップビューコードです:
-(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 *dotstr1=@"0";
if([dotstr isEqualToString:dotstr1])
{
NSLog(@"string 0 is %@",dotstr1);
pinView.image=[UIImage imageNamed:@"greyDot.png"];
NSLog(@"coming here 0");
}
NSString *dotstr2=@"10";
if([dotstr isEqualToString:dotstr2])
{
NSLog(@"string 10 is %@",dotstr2);
pinView.image=[UIImage imageNamed:@"blackDot.png"];
NSLog(@"coming here 10");
}
NSString *dotstr3=@"20";
if([dotstr isEqualToString:dotstr3])
{
NSLog(@"string 20 is %@",dotstr3);
pinView.image=[UIImage imageNamed:@"greendot.png"];
NSLog(@"coming here 20");
}
NSString *dotstr4=@"30";
if([dotstr isEqualToString:dotstr4])
{
NSLog(@"string 30 is %@",dotstr4);
pinView.image=[UIImage imageNamed:@"blueDot.png"];
NSLog(@"coming here 30");
}
NSString *dotstr5=@"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;
}
最初の画面の最初の行には、各行の左側に青い画像が含まれています。マップ ビューで同じものを表示しようとしていますが、マップ ビューでは、青い注釈に灰色の画像タイトルが表示されます。これを行う方法を知っている人はいますか。チュートリアルやサンプル コードはありますか?