2行和按钮在一个iPhone地图标注



我对xcode和iPhone开发相当不熟悉,我想知道是否有可能基本上用你的标准地图callout用一行文本在最右边有一个按钮,并在一个callout内加倍。所以它是一个两层高的标注气泡,上面有两行文字,每一行的最右边都有一个按钮。实际上,我希望第一个可以转到详细信息页面,第二个可以为注释提供方向。有没有一种方法,使自定义callout描述,而不太复杂?

查看异步解决方案博客以获取调出替换实现,尽管它可能比您期望的要做更多的工作。我不认为有一种简单易行的方法可以做到你想要的。

你可以实现委托方法,viewForAnnotation如下

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{
MKAnnotationView *view = nil; 
if(annotation !=mapView.userLocation){
    view = (MKAnnotationView *) 
    [mapView dequeueReusableAnnotationViewWithIdentifier:@"identifier"]; 
    if(nil == view) { 
        view = [[[MKAnnotationView alloc] 
                 initWithAnnotation:annotation reuseIdentifier:@"identifier"] 
                autorelease];           
    }   
    //Custom class for showing title and subtitle
    ParkPlaceMark *currPlaceMark = annotation;
        view.image = [UIImage imageNamed:@"pin.png"];
            //Button at far right corner.
    UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    view.rightCalloutAccessoryView=btnViewVenue;
    view.enabled = YES;
    view.canShowCallout = YES;
    view.multipleTouchEnabled = NO;
}       
return view;
}

注释的自定义类如下

@interface ParkPlaceMark : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *m_title;
NSString *m_subTitle;
int position;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, readwrite) int position;
-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;
- (NSString *)subtitle;
- (NSString *)title;
- (void)setTitle:(NSString *)title;
- (void)setSubTitle:(NSString *)subtitle;
@end

Annotation的自定义类实现

@implementation ParkPlaceMark
@synthesize coordinate;
@synthesize position;
- (NSString *)subtitle{
return m_subTitle;
}
- (NSString *)title{
return m_title;
}
- (void)setTitle:(NSString *)title{
m_title = title;
}
- (void)setSubTitle:(NSString *)subtitle{
m_subTitle = subtitle;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
@end
-(void)viewDidLoad
{
    rightimg.alpha=0;
    wrongimg.alpha=0;
    [scorelable setFont:[UIFont fontWithName:@"Helvetica" size:20]];
    quiz_array = [[NSMutableArray alloc]initWithObjects:@"which animal is called lion?",@"TigerDance_mov_02.png",@"LionDance_mov_11.png",@"cheethau.png",@"1",@"in these three which is the dog?",@"DogLooking_mov_36.png",@"UnicornLeggingSingleLeg_mov_09.png",@"ZeebraHeadShake_ioc_23.png",@"1",@"which animal most humans likes or pets?",@"PigWalk_ioc_08.png",@"RabbitHeadShake_ioc_10.png",@"dog.png",@"3",@"which kind of birds will keep in the houses?",@"egg.png",@"red.png",@"parrot.png",@"3",@"in these which animal are called domestic animal?",@"LionDance_mov_11.png",@"CowWalk_mov_01.png",@"TigerDance_mov_02.png",@"2",@"in these which animals are called wild animals?",@"cow2.png",@"black-horse-black_horse.jpg",@"deer.png",@"3",@"which animal moves slowly?",@"Three.png",@"turtile.png",@"snail.png",@"3",@"which animals eats veg or grass and leaves?",@"deer.png",@"dog.png",@"cat.png",@"1",nil];

    NSString *selected = [quiz_array  objectAtIndex:row];

       NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%d . %@",questionnumber,selected];

    rightAnswer = [[quiz_array objectAtIndex:row+4] intValue];
    [answerimg1 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+1]]];
    [answerimg2 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+2]]];
    [answerimg3 setImage:[UIImage imageNamed:[quiz_array objectAtIndex:row+3]]];
        correctOption = [quiz_array objectAtIndex:(row+rightAnswer)];

    questionlbl.text = activeQuestion;
}

最新更新