views:

3197

answers:

3

I am trying (from my 3rd child in the heirachy) to load the root view with the following. This does not work and I get the following error when the below code is run.

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

Code:

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

This exact same code works on other views, any idea how to debug this.

A: 

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

The unrecognized selector error is telling you that you are sending are attempting to call a method (named clickButton:) that does not exist.

I would suspect a spelling error. I take it that you most likely have a button defined that calls the code to create the 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 have made the mistake before of implementing a -(void) clickButton {} method, but had the message actually sending a parameter as well.

Brad Smith
Sorry I had a typo but still an error, see comment to post below.
Lee Armstrong
A: 
  1. If you have created the button programatically and set the target as clickButton, make sure the clickButton method is present

  2. The clickButton method (according to the error) should take in an argument. So the definition of the method will be

    • (IBAction)clickButton:(id)sender;
  3. If you have mapped the IBAction to an event in IB, you can omit the :(id)sender part

  4. To load the root view controller from any view in a navigation-based application, use

    [[self navigationController:popToRootViewControllerAnimated:YES];

lostInTransit
Sorry as above I had a typo in the code.If I take out all the code now and have a single NSLog that works and I can click the button till my hearts content.The error I now get is...*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MapViewController 0x1172720> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key activityIndicator.'
Lee Armstrong
That means you have an IBOutlet variable called activityIndicator but it is not mapped to a control in the nib file
lostInTransit
Thanks but I don't have one in the code of the current view or the NIB. In the MapView that I am trying to load this does and that has an IBOutlet as that works as I startAnimating that someplace else!???
Lee Armstrong
Ok Strange,I disconnected the activityIndicator in IB and reconnected it and got the following error instead...*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MapViewController 0x111ffa0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key updatedLabel.'However doing the same for this label results in the above :-(
Lee Armstrong
In what class did you create the IBOutlet for the Activity Indicato, and Label? If it was done in a subclass of MapViewController that you implemented, you will need to make sure that the MapViewController's subclass name is in IB, not the name of the superclass. is set to your subclass, although without seeing the code, it's hard to say.
Brad Smith
As Brad said, make sure all the object classes are set properly. This unbinding also happens if you change the name of the class after creating the bindings. Make sure the file's owner is an object of your viewcontroller and do the bindings again.
lostInTransit
Cheers guys, I created a new nib and relinked it all. Must have been a stray!
Lee Armstrong
A: 

Sometimes gdb command "backtrace" could help to find a cause of this error. You have to enter this commmand as "bt" on "backtrace" just after an application crash to print out stack. In my case I had a problem that AVPlayer notification was sent to already deallocated instance , because user selected sound and closed view before sound was played completely , so notification was sent to already deallocated object. Backtrace gave me a clue:

#0  0x34c2c118 in ___forwarding___ ()
#1  0x34bbbc50 in __forwarding_prep_0___ ()
#2  0x33c1163c in -[AVAudioPlayer(AVAudioPlayerPriv) finishedPlaying] ()
#3  0x34bb15c0 in -[NSObject(NSObject) performSelector:withObject:] ()
#4  0x3528431c in __NSThreadPerformPerform ()
#5  0x34bfd294 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#6  0x34bff0e2 in __CFRunLoopDoSources0 ()
#7  0x34c00058 in __CFRunLoopRun ()
#8  0x34ba70c2 in CFRunLoopRunSpecific ()
#9  0x34ba6fd0 in CFRunLoopRunInMode ()
#10 0x3033bf90 in GSEventRunModal ()
#11 0x31213b48 in -[UIApplication _run] ()
#12 0x31211fc0 in UIApplicationMain ()
#13 0x000022e0 in main (argc=1, argv=0x2ffff5e8) at /Users/guntis/Projects/MT/MT/main.m:16

Guntis Liepins

ctrlz