简体   繁体   English

pushViewController不能以编程方式与情节提要一起使用

[英]pushViewController doesn't work programmatically with storyboard

When i push a view using the segues (directly by dragging it on the storyboard) it works fine, and the next view is loaded. 当我使用segues(直接通过在情节提要板上拖动它)推送视图时,它工作正常,并加载了下一个视图。 However, when i try to implement all this programmatically to push a view when i click on the right arrow of the PIN (in Maps), i am a bit confused: 但是,当我尝试以编程方式实现所有这些功能以在单击PIN的右箭头(在地图中)时推送视图时,我有些困惑:

EDIT 编辑

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

i got this error: 我收到此错误:

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

You have to use UIViewController s instance method performSegueWithIdentifier:sender: . 您必须使用UIViewController的实例方法performSegueWithIdentifier:sender: It initiates the segue with the specified identifier from the view controller's storyboard file programmatically. 它以编程方式从视图控制器的情节提要文件中使用指定的标识符启动segue。

Here is the documentation . 这是文档

Example code would be: (assuming you are calling this in a view controller. 示例代码为:(假设您在视图控制器中调用此代码。

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

So for your code it would be: 因此,对于您的代码,它将是:

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

Don't forget to set the segue identifier in the interface builder. 不要忘记在界面构建器中设置segue标识符。 Also, do make sure that you have the same identifier in both your code and the interface builder. 另外,请确保代码和界面生成器中的标识符相同。

Malek is correct. Malek是正确的。 Pfitz example does return Pfitz示例确实返回

Receiver Type 'MyFirstViewController' for instance message does not declare a method with selector performSegueWithIdentifer:sender: 实例消息的接收者类型“ MyFirstViewController”未使用选择器performSegueWithIdentifer:sender声明方法:

This is due to an typo. 这是由于错字。 The correct method is 正确的方法是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM