简体   繁体   中英

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

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: . It initiates the segue with the specified identifier from the view controller's storyboard file programmatically.

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. Also, do make sure that you have the same identifier in both your code and the interface builder.

Malek is correct. Pfitz example does return

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

This is due to an typo. The correct method is

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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