2012-01-22 48 views
1

我正在iOS5中的用戶故事板上的iPhone應用程序。我創建了一個使用帶註釋標註的mapkit的故事板。我可以使用Storyboard編輯器連接按鈕和表格行選擇的push segues。我對MapKit中的自定義標註有經驗,但無法弄清楚如何從標註中推送在故事板中定義的視圖控制器。但是,我打算使用[self.navigationController pushViewController:abc animated:YES]來做到這一點,我需要從故事板獲取視圖控制器或初始化新的視圖控制器。由於沒有NIB名稱,因此我無法訪問NIB名稱。如何訪問故事板中定義的ViewController的實例?有什麼方法可以使用Storyboard編輯器將PUSH Seques連接到自定義地圖註記標註?Mapcall在IOS5中與故事板

在此先感謝。

+1

剛剛發現,說明一個鏈路如何在故事板實例化的ViewController: UIStoryboard *故事板= [UIStoryboard storyboardWithName:@ 「MainStoryboard」 束:一個NSBundle mainBundle]]; myViewController * myVC = [storyboard instantiateViewControllerWithIdentifier:@「myViewController」]; 這工作。一旦使用此代碼實例化了視圖控制器,我就能夠推送視圖控制器。我的問題解決了。 – aullman

+0

請添加您的解決方案作爲問題的答案,然後接受您的答案。接受你自己的回答是可以的。 –

回答

1

您可以在視圖控制器之間創建循環,這些視圖控制器通過控件從一個視圖控制器拖動到另一個視圖控制器而以編程方式執行。然後在MKMapViewDelegate方法- (void)mapView:annotationView:calloutAccessoryControlTapped:中,只要您在故事板中給出了segue標識符,就可以以編程方式執行segue。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    // I've chosen to pass the annotation view as the sender here. 
    // I'm assuming this view controller will be configured with data that 
    // is backing the annotation view. By passing the view, you will be able 
    // to inspect it and it's backing annotation in `prepareForSegue:sender:` 
    [self performSegueWithIdentifier:@"ShowSomeViewController" sender:view]; 
} 
+0

謝謝。這是一個非常好的選擇。我會試試看。 – aullman

1

我添加了一個按鈕,並通過控件拖動它到視圖控制器來執行。之後,我使用按鈕的隱藏屬性,以確保它隱藏。你不能僅僅控制把mapview拖到另一個視圖控制器上。你必須使用一個按鈕。確保你給你的segue一個標識符。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
    [self performSegueWithIdentifier:@"detailSegue" sender:view]; 
} 
+0

我該如何使用它並將一些數據傳遞給segue?我嘗試過使用prepareForSegue,甚至應該執行Segue ...但似乎通過這兩種方法 – user1372829