簡體   English   中英

pushViewController不能以編程方式與情節提要一起使用

[英]pushViewController doesn't work programmatically with storyboard

當我使用segues(直接通過在情節提要板上拖動它)推送視圖時,它工作正常,並加載了下一個視圖。 但是,當我嘗試以編程方式實現所有這些功能以在單擊PIN的右箭頭(在地圖中)時推送視圖時,我有些困惑:

編輯

 -(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:

您必須使用UIViewController的實例方法performSegueWithIdentifier:sender: 它以編程方式從視圖控制器的情節提要文件中使用指定的標識符啟動segue。

這是文檔

示例代碼為:(假設您在視圖控制器中調用此代碼。

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

因此,對於您的代碼,它將是:

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

不要忘記在界面構建器中設置segue標識符。 另外,請確保代碼和界面生成器中的標識符相同。

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

實例消息的接收者類型“ MyFirstViewController”未使用選擇器performSegueWithIdentifer:sender聲明方法:

這是由於錯字。 正確的方法是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM