2011-07-06 62 views
1

我對xcode和iPhone開發相當新,我想知道是否有可能基本上帶有一行文本的標準地圖標註與最右邊的按鈕,並在一個標註內加倍。所以這是一個雙高的標註泡泡,兩行文字互相疊加,每一個都在最右邊有一個按鈕。實際上,我希望第一個轉到詳細信息頁面,第二個轉到指定註釋的方向。有沒有一種方法可以按照描述製作自定義標註而不會太複雜?2個線和按鈕在一個iPhone地圖標註

+0

是否要點擊引腳,它應該顯示具有一行和最右側按鈕的註釋視圖,再次單擊最右側按鈕時,應該重新加載註釋視圖以顯示細節? – iMOBDEV

+0

我希望它在註釋的第一次觸摸時用兩條線和按鈕顯示標註。 – Ryan

回答

0

退房的Asynchrony Solutions Blog爲一個標註替換實現,儘管它可能你的工作比你想做的要多。我不認爲有一個簡單的方法來做你想做的事。

+0

雖然這比我願意做的事情要多(儘管我可以做),但它看起來像是最好的答案也許是這樣做的唯一方法。謝謝。 – Ryan

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 

自定義類實現註釋

@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 
+0

我想你錯過了這個問題的關鍵。我需要兩行文字和兩個按鈕,一個放在另一個上面,在標註內顯示何時插入一個插針。 – Ryan

+0

嘗試以1個註釋視圖作爲主視圖並添加2個註釋視圖作爲該主註釋視圖的子視圖 – iMOBDEV

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; 

} 
相關問題