2012-04-27 37 views
1

Mapkit用法,這裏是我的場景:當用戶在我的地圖上選擇其中一個圖釘,然後選擇與該圖釘相關聯的標註時,用戶將被帶入到另一個ViewController將顯示與他們的選擇相關的信息。確定在地圖上選擇哪個引腳用於繼續

要設置destinationViewController數據,我使用

prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 

這是工作,但我有哪裏我不知道該註釋已選擇的問題。 下面的代碼說明我的問題 - 代碼工作,但我有它硬編碼爲「objectAtIndex:0」,而不是objectAtIndex:「他們選擇了什麼針」

[self.myImageViewController setAddressMessage: [[self.annotations objectAtIndex:0] houseAddress]];   

在prepareForSegue,我怎麼知道哪個引腳他們選擇了?

+0

如果我把一個斷點在我可以看到,「發送者」是取決於哪個銷/選擇標註不同的十六進制值,我需要適當的代碼與該值相關的註釋,並用它作爲一個索引爲我的陣列。 – user1278974 2012-04-27 15:52:46

+0

在此之前,我已經調用[self performSegueWithIdentifier:@「My Image」sender:control];所以它是我需要使用的控制值,但是如何將它與我的數組的索引相關聯? – user1278974 2012-04-27 16:10:04

回答

4

不知道你的代碼的其餘部分,我不知道這是否會工作,但我這是怎麼找到註釋在被壓在註釋視圖的標註的按鈕類似的情況。

-(void)buttonInCalloutWasTapped:(UIButton *)button { 
    if ([[[[button superview] superview] class] isSubclassOfClass:[MKAnnotationView class]]) { 
     MKAnnotation *annotation = [(MKPinAnnotationView *)[[button superview] superview] annotation]; 
     [self.myImageViewController setAddressMessage: [annotation houseAddress]]; 
    } 
} 
+1

謝謝。這對我的代碼只做了一些小小的調整。 MYAnnotation * localannotations = [(MKPinAnnotationView *)[[sender superview] superview] annotation]; – user1278974 2012-04-27 17:11:54