2012-01-09 72 views
1

當我使用segues推送視圖(直接通過在故事板上拖動它)可以正常工作,並且加載下一個視圖。然而,當我嘗試實現這一切編程推視圖時我對PIN的右箭頭點擊(在地圖),我有點困惑:pushViewController無法以編程方式與故事板一起工作

編輯

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    NSLog(@"calloutAccessoryControlTapped: enseigneDeLaStation"); 
    [self performSegueWithIdentifer:@"You identifier" sender:self]; 
} 

我得到這個錯誤:

Receiver Type 'MyFirstViewController' for instance message does not declare a method with selector performSegueWithIdentifer:sender: 

回答

5

你必須使用UIViewController小號實例方法performSegueWithIdentifier:sender:。它以編程方式從視圖控制器的storyboard文件中以指定的標識符啓動segue。

Here is the documentation

示例代碼將是:(假設你是在一個視圖控制器調用此

[self performSegueWithIdentifier:@"Your identifier" sender:self]; 

因此,對於你的代碼將是:

-(IBAction)goToNextView{ 
    NSLog(@"The button is clicked"); 
    [self performSegueWithIdentifier:@"Your identifier" sender:self]; 
} 

不要忘記設置SEGUE標識符,並確保在代碼和接口生成器中都具有相同的標識符

+0

嗨Pfitz,請你說明一個使用例子嗎? thanx – Malloc 2012-01-09 13:20:01

+0

Hi @Malek。我更新了我的答案,並希望現在更清楚 – Pfitz 2012-01-09 13:54:28

+0

Pfitz,實際上,我在評論之前嘗試了它,但出現錯誤:實例消息的Receiver Type'MyFirstViewController'沒有聲明與選擇器相關的方法performSegueWithIdentifer:sender:',also also ,我嘗試在使用地圖時單擊PIN的右箭頭時推送視圖,因此我的代碼位於'calloutAccessoryControlTapped'方法中,我將更新我的帖子以使我的問題清晰。 – Malloc 2012-01-09 14:05:23

3

Malek是正確的Pfitz示例確實返回

Receiver Type 'MyFirstViewController' for instance message does not declare a method with selector performSegueWithIdentifer:sender:

這是由於輸入錯誤。正確的方法是

[self performSegueWithIdentifier:@"You identifier" sender:self]; 
相關問題