`unrecognized selector sent to instance <OBJ_ADR>`after sending `dismissViewControllerAnimated:completion` to a UIViewController
Asked Answered
W

1

2

Lots of similar questions but non with a solution that works in my case.


I try to write a simple FlipSideApp. Just two views with a single button each (flipBtn | flopBtn) to present the other view vice versa. flip on the first view works fine. flop on the other view causes a
unrecognized selector sent to instance 0x6c3adf0.

The App crashes after calling [self dismissViewControllerAnimated:YES completion:nil]; in file FlipSide.m (see code below). Where 0x6c3adf0 is the current address of self which is an instance of FlipSide : UIViewController in that case.

So I think the unrecognized selector mentioned in the error message is the dismissViewControllerAnimated:completion-method.
While typing Xcode's CodeSense "recommends" that method.

According to the UIViewController Class Reference this method is known in iOS 5.0 SDK.
My Deployment Target is 5.0, Device iPhone, Base SDK iOS 5.0, Architecture Standard (arm7).

With a symbolic breakpoint set for all Exceptions the debugger stops at UIApplicationMain in main function. Which is nothing that give me a hint.
Zombie-Objects are enabled. Even when I think memory leaks are not the problem here.

What can I do that makes the selector be recognized?



File: "AppDelegate.m"

#import "FirstViewController.h"

- (BOOL)application:(UIApplication *)application  
                  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

self.window = [[[UIWindow alloc]  
                      initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc]  
                 initWithNibName:@"FirstViewController" bundle:nil] autorelease];

self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}




File: "FirstViewController.h"

@interface FirstViewController : UIViewController

- (IBAction)flipBtn:(id)sender;

@end


File: "FirstViewController.m"

…
- (IBAction)flipBtn:(id)sender {

NSLog(@"%s -- reached --", __PRETTY_FUNCTION__);

FlipSide* flipSide = [[FlipSide alloc] initWithNibName:@"FLipSide" bundle:nil];
[self presentViewController:flipSide animated:YES completion:nil];    

NSLog(@"%s -- done --", __PRETTY_FUNCTION__);
}




File: "FlipSide.h"

@interface FlipSide : UIViewController 

- (IBAction)flopBtn:(id)sender;

@end


File: "FlipSide.m"

#import "FlipSide.h"

- (IBAction)flopBtn:(id)sender {

NSLog(@"%s -- reached --", __PRETTY_FUNCTION__);

NSLog(@"self address is: %@", self);

//  //  //      ??? unrecognized selector sent to instance ???
[self dismissViewControllerAnimated:YES completion:nil]; //  <--

NSLog(@"%s -- done --", __PRETTY_FUNCTION__);
}




Console OutPut is:

-[FirstViewController flipBtn:] -- reached --
-[FirstViewController flipBtn:] -- done --
-[FLipSide flopBtn:] -- reached --
self address is: <FLipSide 0x6c3adf0>
-[FLipSide flopBtn:] -- done --
-[FLipSide flopBtn:]: unrecognized selector sent to instance 0x6c3adf0 
Warfold answered 11/12, 2011 at 21:49 Comment(5)
Try [self.navigationController dismissView...] instead. I've encountered weird memory issues if you call it on the UIViewController instead of the UINavigationController.Cessation
I am sorry that does not help it. My app still crashes with the same error messageWarfold
I experimented a little and found out something: (1) I implemented the exactly same project once again with Automatic Reference Counting (ARC) enabled. That made the (exactly same) code working. (2) After that I shutdown my computer, restarted it and implemented the (exactly same) source code another time but WITHOUT ARC again like I did in the very first time. The unbelievable thing is: After running an ARC enabled project and a shut down my computer. Now the project (itself has still no ARC enabled) runs without errors, warning, problems or that original error message. Why???Warfold
If you re-implemented your code a second time, and it started working, it (barring any really weird edge cases) just means you had a typo of some sort in your original project.Cessation
I don not think so, cause I copied and pasted the source code (It is just of three lines of code). I would not wonder If copying would cause typos but correcting some? - I'll double check that. -- -- Is there a way to check if ARC is enabled during runtime. Or is there any option to check after creation of a project?Warfold
W
3

I got the solution myself!

Knowing it the error message makes sense:
The answer lies in the used XIB-file(s).

Rule of thumb:
Check your GUI-Elements in InterfaceBuilder by right-cklicking or "ctrl"+clicking that all their sent events are connected to existing methods!

If that is not the case the
instance means the GUI element get sent a
unrecognized selector means a non existing method connected to it in InterfaceBuilder. ;-)

Be aware that one event can be connected to several methods. If even one of them is not defined (any longer) you will get that error. Keep this in mind if you delete, rename or change signatures of methods manually. The formerly made connection may still exist.

Warfold answered 12/12, 2011 at 19:21 Comment(3)
Would someone please vote for that answer - I can't (It is forbidden to vote for your own answers).Warfold
You can accept your own answer after a certain period of time, it doesn't need to be voted for necessarily.Irina
Thanx - just discovered that will be possible tomorrow.Warfold

© 2022 - 2024 — McMap. All rights reserved.