-[CLLocation length]: unrecognized selector after table display - ios

Quite unexpectedly after doing some minor modifications, my code has started crashing with:
-[CLLocation length]: unrecognized selector sent to instance 0x1b3739c0.
This happens after the app has completed the display of the cells of a table, more precisely after exiting:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
I tried putting breakpoints in all length accesses in the code, but none of them was caught. I also set a breakpoint on [NSObject(NSObject) doesNotRecognizeSelector:] and this in fact was caught, but gave no information altogether. I also investigated the crash log but the last contact of the crashing thread with my app was in the main function. How may I discover the point of the program producing the crash?

CLLocation does not have a length method, see docs. If it's not your code (you seemed to imply that), maybe it's something in one of your dependencies?
Btw, you should add an exception breakpoint, it should catch that.

In fact one the table textfields was incorrectly a CLLocation. The only catch was the timing of the error. Thank you everyone.

Related

Firguring out reasons for exceptions in Objective-C

After I completed the tutorial: Start Developing iOS Apps Today
I got the same exception asked here: IOS Tutorial Exception (ToDo Sample)
and the app crashed but it would not crash if I started a debugging session and stepped through the code.
2015-05-04 16:09:51.569 ToDoList[9223:67681] -[AddToDoItemViewController textField:]: unrecognized selector sent to instance 0x7fe570d4eff0
2015-05-04 16:09:51.574 ToDoList[9223:67681] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AddToDoItemViewController textField:]: unrecognized selector sent to instance 0x7fe570d4eff0'
Then I solved the mystery by reading out this post: IOS Tutorial Exception (ToDo Sample)
The reason was that I wrongly connected the text field to the #implemenation section instead of to the #interface section and it created some method that I deleted. Of course I forgot about that soon after that.
How could I have figured out myself without knowing anything of the above what was the reason to get that exception and where it came from?
Log message is telling you that something was trying to call -textField: method of your AddToDoItemViewController.
So the first step would be to check if that method is implemented - in your case it was not. You might have been confused by the presence of
#property(weak, nonatomic) IBOutlet UITextField* textField
but auto synthesis for property generates getter with the signature -textField, which is different from -textField: (latter takes one parameter, while former none).
The exception says that you're trying to access the textView property of AddToDoItemViewController, but it doesn't have one.
So your next step would've been to go and check that you have a property like that declared and being an outlet that it's properly connected in the Interface Builder.
Edit:
Sorry I wasn't paying enough attention.
The selector that it's trying to call is textField: so it must be a function starting like that. I assume you set the controller as a TextView delegate but didn't implement the required method.

NSInvalidArgumentException', reason: '-[__NSCFConstantString sizeWithTextStyle:]: unrecognized selector sent to instance 0x170838 [duplicate]

I get the following error while running my app.
'-[NSCFString sizeWithTextStyle:]: unrecognized selector
I have not used sizeWithTextStyle in my entire project.
So what could be wrong?
I get error on return pos; statement below
Code:
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)];
return pos;
}
Error in Console:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString sizeWithTextStyle:]: unrecognized selector sent to instance 0x7044b50'
Because of indentation problem while putting whole crash log here, I am putting the screenshot of the crash log
I think, the problem is somewhere else, not in this line of code. The object is not able to retain itself. Post the code, where you are using the sizeWithTextStyle method
Have you the -all_load flag on your link settings?
This issue comes up a lot. You need to add -all_load and -ObjC to your applications link flags.
*EDIT : *
Crash appears to occur on line:
CGSize textSize = [self.text sizeWithTextStyle:textStyle];
in class: CPTextLayer method: sizeToFit
which is called from within class CPTextLayer method initWithText:
-(id)initWithText:(NSString *)newText style:(CPTextStyle *)newStyle
....
[self sizeToFit];
**try to set with iOS 4 and not with 3.1.3 **
When you have memory management issues (selectors being sent to the wrong instances is one symptom of memory management issues), there are a number of things you can do:
Re-read the Cocoa memory management rules and make sure that you're following them.
Run the static analyser. This will often pick up places where you have neglected the memory management rules.
Try using NSZombieEnabled to find out whether [and when] you are sending messages to unallocated instances.
I am also getting same error but now it's solved.
Need to do simple thing, set the value of Other linker flag.
below I have mention the steps.
Project name - Build Setting - Other linker flag (use search bar to search) - "-ObjC"
You should change your code to use pointers like this:
UIView *pos = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,35.0)];
return pos;
Pay attention to asterisk!
And of course the ; in the end of allocation statement!

How can I find the sender of an unrecognized selector in LLDB?

I'm getting an "unrecognized selector" error that is confusing me.
I know that I can "po" the pointer in LLDB to find out about the receiver. But is there a way to deduce which object is sending this message?
Thanks!
The command bt in the debugger will show you a backtrace (stacktrace), which should give you the class that initiated the message somewhere in that output.
Backtrace doesn't always help if you're dealing with multiple threads - you end up with the backtrace of the exception handler on the main thread which isn't necessarily the one that cause the error.
However, since you know that the particular selector doesn't exist for a particular class, you can cheat a little by using a category to add the selector to the class, then just stick a breakpoint on it.
For example, for this error:
-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x10004fb0
we know that something's trying to call "NSDictionary" with "isEqualToString". So, add this at the end of any file you like, outside any other "#implementation" blocks:
#implementation NSDictionary(debug)
- (BOOL)isEqualToString:(NSString*)theString {
return FALSE;
}
#end
Stick a breakpoint on this, re-run your code and you will get a genuine stack trace. Don't forget to remove the category once you've found the error!

XCode4 Debugger Always Breaks in Main

After upgrading to XCode4 (v. 4.2, 4D199) it seems every time my apps crash while debugging, the debugging points to main(), and the stack is unsymbolicated and useless.
This has been working fine for years, I have no idea what has gone wrong.
I'm using GDB. I also tried the LLDB as per this advice, and it didn't work either (similar, useless stack).
My breakpoints work, I get the full stack, and can inspect variables when my code hits those.
Steps to reproduce:
NB. this happens with my own project, but I'll use Apple's code here to remove that variable from the equation
Download the following sample from Apple: https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007710
In the ImagesViewController class, add the following code to the viewDidLoad method (so it will crash – we want it to crash for this test):
// please note: this code is designed to crash! I want it to crash, to highlight my issue with XCode.
NSMutableArray* test = [NSMutableArray new];
[test insertObject:NULL atIndex:0];
Then run the app & hit the 'Images' row.
It crashes with a message like:
2011-12-23 14:07:02.788 UICatalog[13394:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x37bbb8bf 0x316a11e5 0x37b1020f 0x699f 0x34fac7ff 0x34fb8c39 0x34fb8aa9 0x34fb898f 0x34fb815b 0x34fb7f53 0x34fac673 0x34fac349 0x66c1 0x35026565 0x3509ece7 0x31aec943 0x37b8fa63 0x37b8f6c9 0x37b8e29f 0x37b114dd 0x37b113a5 0x3768ffcd 0x34fa1743 0x2459 0x2418)
terminate called throwing an exception(gdb)
View in xcode:
Thanks to brigadir for pointing me to the solution!
It works well. Here's some screenshots for how to solve this for anyone finding my question:
Tap the plus button of the breakpoints tab
Then click Done

[NSCFArray row]: unrecognized selector sent to instance 0x3953a20

I get a crash with this console message:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[NSCFArray row]:
unrecognized selector sent to instance 0x3953a20'
This happens when I scroll trough a table that gets its data from an array of dictionaries.
Look in the crash log's stack trace to see where exactly this call is happening.
If the variable you're sending -row to isn't actually typed as an NSArray, it's likely that you've failed to follow the memory management rules for that variable. These same symptoms are very commonly caused by that. Something that responds to -row could have existed at one point, been deallocated because you didn't -retain it, and then an NSArray was later allocated in that spot.
Run a "Build & Analyze," and re-re-review the memory management guidelines until you know them in your sleep.
Looks like you are sending a row message to an NSArray. There is no row method defined in the NSArray class. If you are using a table, my guess is you want to send "row" to the indexPath parameter to get the position and then get the data at that position in your data array:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// first row will be like 0
NSUInteger row = [indexPath row];
// get the same row position in your data array
id data = [YOUR_DATA_ARRAY objectAtIndex:row];
}
That will give you the numeric position of the row. One caveat: "row" is not part of the base NSIndexPath class. It's added as a category in UIKit.

Resources