我是xcode和iPhone开发的新手,我想知道是否有可能基本上使用一行文本和最右边的按钮来标准地图标注,并在一个标注内加倍。所以它是一个双高的标注气泡,两行文字在彼此的顶部,每一行都有一个最右边的按钮。实际上,我希望第一个转到详细信息页面,第二个转到提供注释的方向。有没有办法按照描述制作自定义标注而不会太复杂?
答案 0 :(得分:0)
您可以实现委托方法,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
答案 1 :(得分:0)
查看Asynchrony Solutions Blog以获取标注替换实施,但这可能比您希望的更多。我不认为有一种简单的方法可以做你想做的事。
答案 2 :(得分:0)
-(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;
}