Debug pushViewController

I am trying (from my third child in heirachy) to load a root view like this. It doesn't work and I get the following error when running below code.

-[DetailViewController clickButton:]: unrecognized selector sent to instance 0x1161e00' 

      

the code:

 MapViewController *dvController = [[MapViewController alloc] initWithNibName:@"MapView" bundle:[NSBundle mainBundle]];
        [self.navigationController pushViewController:dvController animated:YES];
        [dvController release];
        dvController = nil;

      

This exact code works with other views, any idea of ​​debugging this.

+1


a source to share


2 answers


The code you wrote to create the MapViewController and route it to the view controller stack is correct.

An unrecognized selector error is telling you that you are submitting an attempt to call a method (named clickButton :) that does not exist.

I would suspect a spelling mistake. I believe that you most likely specified a button that calls the code to create a new view. The method should look like this:



-(void) clickButton: (id) sender {
    MapViewController *dvController = [[MapViewController alloc] initWithNibName:@"MapView"  bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];
    [dvController release];
    dvController = nil;
}

      

I would check that you have the ": (id) sender" part. I made a mistake before implementing the a- (void) clickButton {} method, but the message did send the parameter.

+1


a source


  • If you created your program programmatically and set the target to be clickButton, make sure you have the clickButton method at your disposal.

  • The clickButton method (according to the error) must take an argument. So the method definition would be

    • (IBAction) ClickButton: (ID) of the sender;
  • If you mapped the IBAction to an event in IB, you can omit the sender part: (id)

  • To load a root view controller from any view in a nav app use

    [[self navigationController: popToRootViewControllerAnimated: YES];



0


a source







All Articles