Terminating app due to uncaught exception 'NSUnknownKeyException' [duplicate] - iphone

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I'm using a tutorial to write a fairly simple app. I copied the app to my work computer today. It was working perfectly on my laptop last night, but today I get this error. I tried gutting nearly all of the code, and even deleted everything in the didFinishLaunchingWithOptions function, but I still get this error. I don't even have a navBar declared anywhere! I assume there's some kind of project or file setting outside of the code that is the problem?
2011-11-22 14:39:32.294 LetsEat[15320:b603] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<LetsEatAppDelegate 0x5a824a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navBar.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00fa45a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010f8313 objc_exception_throw + 44
2 CoreFoundation 0x00fa44e1 -[NSException raise] + 17
3 Foundation 0x0079f677 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x0079f5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x0021b30c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00f1a8cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x00219d23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x0021bab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x0002117a -[UIApplication _loadMainNibFile] + 172
10 UIKit 0x00021cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
11 UIKit 0x0002c617 -[UIApplication handleEvent:withNewEvent:] + 1533
12 UIKit 0x00024abf -[UIApplication sendEvent:] + 71
13 UIKit 0x00029f2e _UIApplicationHandleEvent + 7576
14 GraphicsServices 0x011dd992 PurpleEventCallback + 1550
15 CoreFoundation 0x00f85944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16 CoreFoundation 0x00ee5cf7 __CFRunLoopDoSource1 + 215
17 CoreFoundation 0x00ee2f83 __CFRunLoopRun + 979
18 CoreFoundation 0x00ee2840 CFRunLoopRunSpecific + 208
19 CoreFoundation 0x00ee2761 CFRunLoopRunInMode + 97
20 UIKit 0x000217d2 -[UIApplication _run] + 623
21 UIKit 0x0002dc93 UIApplicationMain + 1160
22 LetsEat 0x00001c99 main + 121
23 LetsEat 0x00001c15 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
(gdb)
EDIT: This is the top of my delegate.m file. As you can see it's all boilerplate:
#import "LetsEatAppDelegate.h"
//#import "ItemsViewController.h"
#implementation LetsEatAppDelegate
#synthesize window = _window;
#synthesize managedObjectContext = __managedObjectContext;
#synthesize managedObjectModel = __managedObjectModel;
#synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
I removed every other file in the project and still get this error.
EDIT 2
As it now stands, I only get this error on my work machine. The exact same files run perfectly on my home laptop. Same version of XCode (4.2.1)

Reset Content and Setting didn't work.
Here's what wasted 2 hrs of my late night time:
I had connected an UIControl outlet in the interface builder to the IBOutlet in the xib's owner. For some reason, the IBOutlet was deleted from the owner, but the reference to the outlet remained dangling in the xib. This would always give me the error
"Terminating app due to uncaught exception 'NSUnknownKeyException'"
Lesson learnt: When deleting any outlets for vars in the implementation, make sure to unhook the respective connection in the IB
Update: (26 Jan 2015)
There's a good reason why the Interface Builder or the nibs behave this way, and I realized the why, today.
If you have an IBOutlet in TheBaseClass, and you have a nib or scene in the storyboard for a TheSubClass, there are two ways (hacks) available for you to connect this outlet:
Under the Identity Inspector, name the "Custom Class" identifier to TheBaseClass, connect the outlet, then set the Class name in the "Custom Class" section to TheSubclass
Add the IBOutlet in your TheSubclass code, connect it to the ui element in the nib, add the IBOutlet code in TheBaseClass, delete that code in TheSubClass
When I came across this answer it just fell in place, as to why Apple would let this dangling reference problem remain as is. Because, this is not a bug. This is a feature.

Fixed - went to iOS Simulator > Reset Content and Setting

I had this issue and found that I had set the 'Main Interface' and it was causing an issue.
To change this setting click on your project (in the left hand file browser). The center area should now display the 'Summary' of settings for your project. This is the same area where you would change the iOS Application Target or the Supported Device Orientations. Under the section 'iPhone/ iPod Deployment Info' clear the 'Main Interface' drop down, leaving it blank. This fixed the issue for me.
Good luck.

The issue is in your nib file. There is an old connection from the LetsEatAppDelegate to the navBar.
I am not sure how your app is set up, there may be an LetsEatAppDelegate object in one of your nib files, or there could be a file owner with the class set to LetsEatAppDelegate
4 Foundation 0x0079f5e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x0021b30c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00f1a8cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x00219d23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x0021bab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
2011-11-22 14:39:32.294 LetsEat[15320:b603] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<LetsEatAppDelegate 0x5a824a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navBar.'
*** Call stack at first throw:

Oh man. I was having the same problem after removing #properties and/or IBActions and it was driving me crazy! Warkst was right on the money. Go to the problem view controller, click on the orange ball and deselect any dangling references you find. You may need to scroll down to find them all. This solved my problem. Thanks a million.

Clearing "Main Interface" also solved the issue for me. You may need to perform a "Clean" after clearing "Main Interface" and before building.

I meet this problem too,
1.In AppDelegate method
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
the rootViewController is init by this methods initWithNibName..... but actually the nib file is not exist, so the exception throw..
2.When viewController load view it crashes
I guess maybe because I deleted the xib file,then the view controller still init with nib file.. so I add the -(void)load view methods. and it is ok now..ps:I reset the simulator,but it doesn't work.
Hope this help.

I faced the same problem recently. All my outlet connections where perfectly fine though. I finally made it by making decent CLEAN of the project.
Thanks to #Robert Wohnoutka and this post: How to Delete Derived Data and Clean Project in Xcode 5 and Xcode 6?

Related

UITableView crash during animation, fixing solution found but doesn't locate root cause, wonder why?

In my iphone project I always insert UITableView into the view controller as IBOutlet, most times it works well, but random crash will occur when do animation invoked by popToRootViewControllerAnimated. Track it by zombie, find the crash dues to UITableView instance has been deallocated, but there are still system events sent to it, so crash.
I always resolve such issue by either of the following methods in view controller's dealloc method.
tableView.dataSource = nil; (work for most cases)
or
[tableView removeFromSuperview]; (work for some special cases)
Although the crash can be fixed by the above change, but I am still confusing.
Is it apple's defect that we need to set its dataSource to nil explicitly to avoid crash? Or maybe our own app code has problem?
Anyone who has also experienced such crash, do you know what's the root cause?
Any idea or discussion will be appreciated, thanks in advance.
enter code here
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x626f6d37
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x33fe0c98 objc_msgSend + 16
1 UIKit 0x364538f6 -[UITableView(UITableViewInternal) _spacingForExtraSeparators] + 58
2 UIKit 0x3645337a -[UITableView(_UITableViewPrivate) _adjustExtraSeparators] + 158
3 UIKit 0x36453218 -[UITableView layoutSubviews] + 40
4 UIKit 0x363ff5f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 20
5 CoreFoundation 0x30e13efc -[NSObject(NSObject) performSelector:withObject:] + 16
6 QuartzCore 0x33d8dbae -[CALayer layoutSublayers] + 114
7 QuartzCore 0x33d8d966 CALayerLayoutIfNeeded + 178
8 QuartzCore 0x33d931be CA::Context::commit_transaction(CA::Transaction*) + 206
9 QuartzCore 0x33d92fd0 CA::Transaction::commit() + 184
10 QuartzCore 0x33d8c04e CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 50
11 CoreFoundation 0x30e7da2e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
12 CoreFoundation 0x30e7f45e __CFRunLoopDoObservers + 406
13 CoreFoundation 0x30e80754 __CFRunLoopRun + 848
14 CoreFoundation 0x30e10ebc CFRunLoopRunSpecific + 224
15 CoreFoundation 0x30e10dc4 CFRunLoopRunInMode + 52
16 GraphicsServices 0x34efe418 GSEventRunModal + 108
17 GraphicsServices 0x34efe4c4 GSEventRun + 56
18 UIKit 0x36428d62 -[UIApplication _run] + 398
19 UIKit 0x36426800 UIApplicationMain + 664
20 ScoutFree 0x00099558 0x1000 + 623960
21 ScoutFree 0x00003618 0x1000 + 9752
You forgot to set tableView.delegate to nil, so you can still get crashes, especially when animation is going(as it asks now dead controller for new rows). It's not Apple's defect, it's programmer responsibility to clear out those references. So set dataSource and delegate properties of tableView to nil, then release tableview(by setting corresponding property to nil or releasing iVar like this [_iVar release]; iVar = nil;)
First of all, the ONLY things you should be calling in dealloc are release on your ivars, unregistering for NSNotificationCenter notifications (if registered in init), or setting delegates of UIWebViews and UIScrollView to nil (as suggested by Apple's documentation). If your UIViewController is the delegate/data source of your tableview, there is no need to set those to nil in dealloc (or anywhere else), as when the view controller is destroyed, your guaranteed it won't send any rogue messages, and you're equally guaranteed that the delegate/data source of the table view won't get destroyed before the table view does.
It's highly unlikely that the defect is Apples. What OS are you targeting? If you're using ARC, you really should have few occasions when you need to be mucking around in dealloc. If you symbolicate your crash log, you will get the line numbers and classes from your app that is causing the crash. Symbolicating in Xcode 4 is really simple, you can find info on that here: Symbolicating iPhone App Crash Reports
What do you mean you always insert the tableview as an IBOutlet? If it's an IBOutlet, that implies that you have a table view in a nib file, in which case the table view gets created for you when the nib is unloaded. If you are trying to remove the table view and re-add it to the view for the purpose of updating its information, this is not the correct approach: simply calling reloadData will do this for you, and go through all of the delegate methods again. Are the delegate and data source an object OTHER than the view controller controlling your table?

iPhone Crash stack trace VS Crash report

Just spent some time... on a crash, without understanding it. That's a classic:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000010
Which leads me to a memory issue, addressing the invalid adress 0x10
What bothers me is that I have crash report and stack trace, which differ:
The crash report, sent by user (symbolicated successfully, that happens) :
Thread 0 Crashed:
0 libobjc.A.dylib 0x000027d8 objc_msgSend + 16
1 UIKit 0x0005e9d2 -[UIViewAnimationState animationDidStop:finished:] + 54
2 QuartzCore 0x0002d8c2 run_animation_callbacks(double, void*) + 286
3 QuartzCore 0x0002d764 CA::timer_callback(__CFRunLoopTimer*, void*) + 116
4 CoreFoundation 0x000567f4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
5 CoreFoundation 0x000562a6 __CFRunLoopDoTimer + 854
6 CoreFoundation 0x0002779e __CFRunLoopRun + 1082
7 CoreFoundation 0x00027270 CFRunLoopRunSpecific + 224
8 CoreFoundation 0x00027178 CFRunLoopRunInMode + 52
9 GraphicsServices 0x000045ec GSEventRunModal + 108
10 GraphicsServices 0x00004698 GSEventRun + 56
11 UIKit 0x0000411c -[UIApplication _run] + 396
12 UIKit 0x00002128 UIApplicationMain + 664
13 MyApp 0x00003158 main (main.m:13)
14 MyApp 0x00003120 0x1000 + 8480
The crash stack trace (catched live by an Exception Handler)
0 MyApp 0x000d79c3 0x0 + 883139
1 MyApp 0x000d790b 0x0 + 882955
2 libSystem.B.dylib 0x302765d3 _sigtramp + 42
3 UIKit 0x31eab9d9 -[UIViewAnimationState animationDidStop:finished:] + 60
4 QuartzCore 0x33a178c9 _ZL23run_animation_callbacksdPv + 292
5 QuartzCore 0x33a1776b _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 122
6 CoreFoundation 0x3084e7fb __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
7 CoreFoundation 0x3084e2ad __CFRunLoopDoTimer + 860
8 CoreFoundation 0x3081f7a5 __CFRunLoopRun + 1088
9 CoreFoundation 0x3081f277 CFRunLoopRunSpecific + 230
10 CoreFoundation 0x3081f17f CFRunLoopRunInMode + 58
11 GraphicsServices 0x31e445f3 GSEventRunModal + 114
12 GraphicsServices 0x31e4469f GSEventRun + 62
13 UIKit 0x31e51123 -[UIApplication _run] + 402
14 UIKit 0x31e4f12f UIApplicationMain + 670
15 MyApp 0x0000315f 0x0 + 12639
16 MyApp 0x00003128 0x0 + 12584
Both differ, and the stack trace points to the crash in my code, but at addresses I can neither symbolicate nor identify. I think the crash report indicates that a message was sent to a released instance... Probably related to the use of :
+ (void)setAnimationDelegate:(id)delegate
+ (void)setAnimationDidStopSelector:(SEL)selector
So here (finally!) are my questions:
What explains the differences between logs? (libobjc.A vs libSystem.B ??)
Does the SIGBUS comes from my code or from UIKit?
How can I decipher the stack trace upper addresses (0x000d79??, which atos doesn't resolve)
Is that what I think, an issue related to an animation failing to end? similar to this > How to unset delegate on UIView setAnimationDelegate: call?
AFAIK, setAnimationDelegate is supposed to retain delegate... Someone to confirm?
EDIT: I can't use NSZombiesEnabled, this is a crash report from a published app, a crash that I didn't manage to reproduce on development environment. I just have these logs to diagnose.
Whenever I see objc_msgSend at the top, my trust of the remaining stack is low, as the error that gives this tends to do bad things to the stack.
GuardMalloc is good for this since the attempt to do anything with deallocated space will crash the app immediately in the debugger. The stack will be intact. (This makes the app very slow, but it is a very powerful tool.)
The two stacks are the same up to the UIViewAnimationState method call. The version that came from your exception handler is showing C++ mangled names instead of the regular names shown in the crash log.
(As I understand it) _sigtramp is the system's method of calling your signal handler and is short for Signal Trampoline. The stack entries beyond that are probably your signal-handler code.
Answering my own question, weeks laters, since I had no relevant answers, most are guesses, I wished I had more precise answers, but I guess my question was unclear :
Difference is coming from the origin of the log, a sighandler vs CrashReporter service, which are happening at different times, then the stack traces are slightly different.
SIGBUS comes from UIKit, but chances are big that's on a callback initiated from my code that ends on a released object. These kind of stack traces are a pain to debug when you can't reproduce the issue, since it basically tells you "I'm crashing somewhere because of an animation", which one, where... I still didn't figured precisely. Could be anywhere, and also could be an Apple iOS bug.
The first addresses in the stack are just a dead-end where any SIGBUS stack-trace ends when a released object is called. They differs across compilations (versions), but are the same on any device, That's why they can't be symbolicated. (I would love to have a technical explanation of this, instead of my guess)
& 5. I guess I solved this bug byt being more "agressive" on canceling animations in certain cases like on deallocation of some Views...
Hope that helps someone.
You should try NSZombie, to get information about what object you've released. This is a very useful tool when you get EXC_BAD_ACCESS.
To activate NSZombie do the following:
Get info of the executable.
Go to the arguments tab.
In the "Variables to be set in the environment:" section add:
Name: NSZombieEnabled
Value: YES
Then run your app as usual and when it crashes it should tell you which deallocated object received the message.
1. I'm not 100% sure but I think the discrepancy is due to how the application is being run. In the second log it looks like you're running the application via XCode in debug mode, a sigtramp signal has been sent to indicate a EXC_BAD_ACCESS error.
2. Your code - the error may come from the UIKit library but it's a result of a problem with your usage.
3. This is where NSZombieEnabled will make your life a lot easier! If you run your application with the NSZombieEnabled flag set XCode will keep 'zombie' objects in place of deallocated objects. When a zombie object is sent a message the process will trap the error and let you know exactly what object was sent the message.
If you're using XCode 4 enable NSZombieEnabled using the following instructions...
How do I set up NSZombieEnabled in Xcode 4?
For older versions follow these instructions...
http://www.cocoadev.com/index.pl?NSZombieEnabled
4. It does indeed appear that your animation delegate has been deallocated prior to the animation completing.

this class is not key value coding-compliant for the key authView [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
When i run my app on simulator it runs well, when i try with device doesn't work and i get these errors:
NOTE: i didn't find any kind of class authView in my code
2011-02-24 12:04:14.472 TestP[473:307] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestP 0x19d2b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key authView.'
*** Call stack at first throw:
(
0 CoreFoundation 0x33ac0987 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3347b49d objc_exception_throw + 24
2 CoreFoundation 0x33ac0705 -[NSException dealloc] + 0
3 Foundation 0x3367db4f -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 182
4 Foundation 0x3367d03b _NSSetUsingKeyValueSetter + 90
5 Foundation 0x3367eda3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 194
6 Foundation 0x33630b17 -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 130
7 UIKit 0x3224c60f -[UIRuntimeOutletConnection connect] + 66
8 CoreFoundation 0x33a63fc7 -[NSObject(NSObject) performSelector:] + 18
9 CoreFoundation 0x33a6cd51 -[NSArray makeObjectsPerformSelector:] + 388
10 UIKit 0x3224b577 -[UINib instantiateWithOwner:options:] + 586
11 UIKit 0x3224cb39 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 92
12 UIKit 0x3209e871 -[UIApplication _loadMainNibFile] + 96
13 UIKit 0x3209a1fd -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 180
14 UIKit 0x3206648b -[UIApplication handleEvent:withNewEvent:] + 1114
15 UIKit 0x32065ec9 -[UIApplication sendEvent:] + 44
16 UIKit 0x32065907 _UIApplicationHandleEvent + 5090
17 GraphicsServices 0x33b0ef03 PurpleEventCallback + 666
18 CoreFoundation 0x33a556ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
19 CoreFoundation 0x33a556c3 __CFRunLoopDoSource1 + 166
20 CoreFoundation 0x33a47f7d __CFRunLoopRun + 520
21 CoreFoundation 0x33a47c87 CFRunLoopRunSpecific + 230
22 CoreFoundation 0x33a47b8f CFRunLoopRunInMode + 58
23 UIKit 0x32099309 -[UIApplication _run] + 380
24 UIKit 0x32096e93 UIApplicationMain + 670
25 TestP 0x00002213 main + 98
26 TestP 0x000021ac start + 40
)
terminate called after throwing an instance of 'NSException'
You've probably got your File's Owner stuff messed up in your xibs. This exception is getting thrown during nib unarchiving (as evidenced by +[UINib...] in the backtrace). It's attempting to hook up your IBOutlets that you defined.
One of your views is set up to be the authView of the the File's Owner. However, when it's time to unarchive the nib, the owner doesn't have an authView property, so the unarchiving is failing.
#Dave DeLong pointed out right.
Workaround
Find when the exception thrown, which viewController is being loaded.
Then check the nib file of the viewController, there must be an IBOutlet attached in xib but might be missed in the viewController.h file or might be some control which was attached is missing in xib file.
Why running in Simulator? Sometimes it ends in messing up.
Just do the steps
Build -> Clean
Build -> Clean All Targets
Now it runs the real code, may be issue got resolve on device also or may be it start throwing exception on simulator also in case if there is really an issue. (I already have mentioned workaround)
This is how I solved this problem. I went into my 'Story Board' file and selected the view that was causing the problems. I then clicked on the Connections Inspector tab and you will see connection(s) with exclamation points to the right instead of solid circles. Remove these and make adjustments if necessary. Save>Run your app and should work. Hope this helps :)
I think that one possible cause for raising that exception is when you have changed the name of some IBOutlet variable after the storyboard connections are already done. Thus the UI element in the storyboard is still referencing to the old variable name. I solved this for me by checking the XML representation of the storyboard (Right click on your .storyboard file and open it as Source Code) and deleting the old (unneeded) IBOutlet variable name.
For example let say you have one UITextField on the storyboard and have the corresponding property for it:
#property (retain, nonatomic) IBOutlet UItextField *myTextField;
You connect the UI element in the storyboard to that property and then you decide to rename somehow the variable. Now if you right click on your UITextField in the storyboard, you will notice that there exists two referencing outlets - the old one and the new one. You can delete the old one by clicking 'x' sign in the Connections Inspector or by editing the XML variant of the storyboard file.
something went wrong when in xcode 4 with some reference , cause i declared IBOutlet that reference authView then run and it worked!, then i removed the IBOutlet declaration and worked well
I just cleaned the project and deleted the app from the device and it worked again. Error was referencing a view that i had already removed.
You have probably created an IBOutlet, then deleted it, then linked a new one, but in the xib 'Inspector' you forgot to delete the link and now have a duplicate IBOutlet ref that the compiler cannot find.
i have found these errors arise mostly when you connect properties, edit them, and connect them again.. analyse your connection inspector for unexpected values, that remain from your previously created and destroyed connection.
In my case it was even more spooky. I had a XIB associated to the VC that I had removed completely as went for code-only. Run on Simulator nicely but would crash on Device systematically.
So I clean, rebuild, closed XCode, went for a snack and shout at the mac. Nothing, the compiler kept pointing to an inexistent button on an inexistent XIB.
Tried by changing the name of the class and that worked!
It seems that your Interface Builder did not work properly.
As suggested before, try by cleaning and rebuild. If it doesn´t work, I´d suggest you to re-create your xib interface. It worked for me in a similar occasion.

Objective-C Category Causing unrecognized selector

My project has a UIImage category function that I want to call from another class. I properly import the header file for the image category and I get the project to compile with no warning.
The problem is that when I call the UIImage category function I seen an unrecognized selector error with a NSInvalidArgumentException. Why am I seeing this if I've properly linked everything?
#import <UIKit/UIKit.h>
#interface UIImage (DRShare)
+ (UIImage*) imageNamed:(NSString*)name;
#end
#implementation UIImage (DRShare)
+ (UIImage*) imageNamedDR:(NSString*)name{
CGFloat s = 1.0f;
if([[UIScreen mainScreen] respondsToSelector:#selector(scale)]){
s = [[UIScreen mainScreen] scale];
}
NSString *path = [NSString stringWithFormat:#"%#%#%#.png",kImagesPath,name,s > 1 ? #"#2x":#""];
return [UIImage imageWithContentsOfFile:DRBUNDLE(path)];
}
#end
file that calls it:
backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamedDR:#"Share Popup Background"]];
exception raised:
2010-10-22 11:51:02.880 Stuff[11432:207] +[UIImage imageNamedDR:]: unrecognized selector sent to class 0x1f8e938
2010-10-22 11:51:02.883 Stuff[11432:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIImage imageNamedDR:]: unrecognized selector sent to class 0x1f8e938'
*** Call stack at first throw:
(
0 CoreFoundation 0x02e65b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02fb540e objc_exception_throw + 47
2 CoreFoundation 0x02e6776b +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02dd72b6 ___forwarding___ + 966
4 CoreFoundation 0x02dd6e72 _CF_forwarding_prep_0 + 50
5 TapTapShare 0x0001291c -[DRShareViewController backgroundView] + 127
6 TapTapShare 0x00012343 -[DRShareViewController loadView] + 639
7 UIKit 0x0044f54f -[UIViewController view] + 56
8 UIKit 0x0044d9f4 -[UIViewController contentScrollView] + 42
9 UIKit 0x0045d7e2 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
10 UIKit 0x0045bea3 -[UINavigationController _layoutViewController:] + 43
11 UIKit 0x0045d12d -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
12 UIKit 0x00457ccd -[UINavigationController _startDeferredTransitionIfNeeded] + 266
13 UIKit 0x00574b55 -[UILayoutContainerView layoutSubviews] + 226
14 QuartzCore 0x02616481 -[CALayer layoutSublayers] + 177
15 QuartzCore 0x026161b1 CALayerLayoutIfNeeded + 220
16 QuartzCore 0x026160bd -[CALayer layoutIfNeeded] + 111
A couple possibilities:
You did not link UIImage+TTShare.m into your target. So while you have the header, you're not compiling the implementation.
If this is part of a static library, you need to add -all_load to the Other Linker Flags build setting for the app linking against the library.
If you want to use Category method, you must add -ObjC to the Other Linker Flags build setting of your APP.
I had the same issue and had to apply this fix as well.
My NSDate-Extensions.m source file wasn't compiling so I had to go into Project Settings, then select the appropriate target, then click the "Build Phases" tab, then expand the "Compile Sources" items, then click the + symbol and manually add my NSDate-Extensions.m file.
I had this error message and I am using Cocoapods. To fix the error, I just needed to call pod install again to create all the necessary linking correctly.
Another possibility.
You have the implementation of category but do not have an interface.
I mean you forgot to declare in *.h the interface of your category.
Yet another possibility:
This is almost too embarrassing to admit, but just in case someone might have done the same silly mistake:
I was copying code from one project to another, and by mistake I had pasted the same source code in the .h file and the .m file (in both I had put the code meant for the .h file). I fixed my .m file and it worked.
May be because you write imageNamed instead of imageNamedDR in the interface..
The sdk hybrid project created on the basis of oc will crash when it is called by the swift file in the sdk-related hybrid demo project, prompting that the oc classification method in the sdk cannot be found. I try to put the compiled package in the link binary with libraries(build phase-link binary with libraries), it works! It is not enough to just set the dependencies of the demo to associate the SDK. It can be regarded as a pit of mixed sdk and mixed demo project!

iphone iOS4 breaking app

I have an application that has been running fine since its launch over a year ago.
I developed it with iphone iOS 2.2.1 originally and tested and kept selling it up until 3.2 without issues.
Now it fails to launch with iOS4.
the app uses a non standard size for a UIPickerView (I don't think that's the problem but just mention it as you will see some complaint in the console output). It's also giving previously non reported NSAutoreleasePool warnings.
But the culprit seems to be when resizing the interface to the new iphone screen resolution (at least what I get from the console)
I know I have to do some research of my own but iOS4 has been out for so little and I have been very absorbed learning and developing my first app for android (so I have not tested this particular code, after a year+ this app only sells a few copies a day) that I thought it didn't harm to ask around here to check if someone has some info or has run into it already.
First, this is the console output when build and run with XCODE 3.2.3 and BASE SDK 3.2, runs without problem
2010-06-22 23:25:55.619 metalsandmaterials[82956:207] ******* Accessibility Status Changed: On
2010-06-22 23:25:55.710 metalsandmaterials[82956:207] ********** Loading AX for: xxxxxxxxx
But trying to run it with iOS4 gives this beauty:
2010-06-22 23:15:52.488 metalsandmaterials[80149:207] ******* Accessibility Status Changed: On
2010-06-22 23:15:52.546 metalsandmaterials[80149:207] ********** Loading AX for: XXXXXXX ************
2010-06-22 23:15:53.003 metalsandmaterials[80149:207] * -[NSAutoreleasePool release]: This pool has already been released, do not drain it (double release).
2010-06-22 23:15:53.005 metalsandmaterials[80149:207] * -[NSAutoreleasePool release]: This pool has already been released, do not drain it (double release).
2010-06-22 23:15:53.008 metalsandmaterials[80149:207] -[UIPickerView setFrame:]: invalid height value 50.0 pinned to 162.0
Right here! [UIIageView scale]
2010-06-22 23:15:53.011 metalsandmaterials[80149:207] -[UIImageView scale]: unrecognized selector sent to instance 0x5ac47a0
2010-06-22 23:15:53.013 metalsandmaterials[80149:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView scale]: unrecognized selector sent to instance 0x5ac47a0'
Call stack at first throw:
(
0 CoreFoundation 0x025f5919 exceptionPreprocess + 185
1 libobjc.A.dylib 0x027435de objc_exception_throw + 47
2 CoreFoundation 0x025f742b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02567116 ___forwarding_ + 966
4 CoreFoundation 0x02566cd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x0039a8e3 -[UIImageView setImage:] + 250
6 UIKit 0x0039b63e -[UIImageView initWithImage:] + 161
7 UIKit 0x05f286ce -[UIImageViewAccessibility(SafeCategory) initWithImage:] + 70
8 metalsandmaterials 0x0000bf09 -[TVCResults init] + 1841
9 metalsandmaterials 0x00002b8c -[UIVCalcHolder init] + 258
10 metalsandmaterials 0x00002758 -[CalcTestAppDelegate applicationDidFinishLaunching:] + 649
11 UIKit 0x002d759c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
12 UIKit 0x002d99a1 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 346
13 UIKit 0x002e3452 -[UIApplication handleEvent:withNewEvent:] + 1958
14 UIKit 0x002dc074 -[UIApplication sendEvent:] + 71
15 UIKit 0x002e0ac4 _UIApplicationHandleEvent + 7495
16 GraphicsServices 0x02de1afa PurpleEventCallback + 1578
17 CoreFoundation 0x025d6dc4 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
18 CoreFoundation 0x02537737 __CFRunLoopDoSource1 + 215
19 CoreFoundation 0x025349c3 __CFRunLoopRun + 979
20 CoreFoundation 0x02534280 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x025341a1 CFRunLoopRunInMode + 97
22 UIKit 0x002d9226 -[UIApplication _run] + 625
23 UIKit 0x002e4b58 UIApplicationMain + 1160
24 metalsandmaterials 0x000024ac main + 230
25 metalsandmaterials 0x000023bd start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
kill
kill
So this scale method is new to uiimageview? why wouldn't it work? has anyone run into this already?
ANY HELP IS EXTREMELY APPRECIATED
best regards
david
You get a message "xxxxxx does not recognize selector yyyyyy" usually when an object has been released but you are still trying to use it. At that point because the memory is random, the system thinks it's some other random kind of object (like UIImage). Thus it's a red herring, a sign that something else is wrong and you are over-releasing an object.
There's no way you are getting those weird autorelease messages unless you are doing SOMETHING with a custom autorelease pool. Fess up, what are you doing with an NSAutoreleasePool in your code?
I think they are probably related to the "does not recognize selector" messages since you may be over-releasing things because of this.
Well, for your first issue with the NSAutoreleasePool, I would use instruments so you can trace where the extra drains/releases are coming from.
Your second issue doesNotRecognizeSelector is telling you that the selector that is being called doesn't exist (or lost scope). I would use the debugger so you can, again, trace that code execution.
Ok, I left if at adding a -(void)scale to a subclass of UIImageView and using this new class. Tested it, works fine on 2.2.1, 3.2 and ios4, both on simulator, iphone touch 3g with ios4 and ipad with ios3.2.
I still need to get ahold of an iphone4 and see if some weird layout problem comes across (I still believe the problems appeared when the Os want to blow things up to the new retina display).
Not being in the US is going to make it a tad hard though
Could I be that you somewhere set the image property of an imageView to another UIImageView (as opposed to an UIImage)?
After all UIImageView does not respond to :scale, but UIImage does.