-1

i know this question was asked several times, and i know the cause that it is calling the selector that was not belong to the class.

But, i want to know the best way to rectify these type of errors. I'm getting the following error in debug console:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController length]: unrecognized selector sent to instance 0x76908e0'

I'm sure, i didn't called the length property anywhere in the code written in this controller.

I tried to debug it using line by line and it crashes somewhere in the binary and i am not able to get the exact cause of crashing the app.

I also tried to run the application with NSZombieEnabled but didn't get any success with this as well.

Can anybody help me in how to get out of these type of issues? What is the best way to know the cause?

Thanks in advance.

************ Resolved ****************

I added the the following UITableViewDelegate method, but not returning anythign in this:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

}

It is causing the crash. I got this when i was just reading the whole source. Thanks all for your great support.

Vinay Jain
  • 2,644
  • 3
  • 26
  • 44
  • add some code where exactly your app crashes? – Rajesh Feb 26 '14 at 07:24
  • 1
    It maybe a object which has an length method is dealloced, but it is still be used, the object it point to is an ViewController object. – KudoCC Feb 26 '14 at 07:26
  • Add exception breakpoint in Xcode and try to catch the crash. Check for Xcode4/5 related answer:[How to add a breakpoint to objc_exception_throw?](http://stackoverflow.com/questions/1163981/how-to-add-a-breakpoint-to-objc-exception-throw) – Amar Feb 26 '14 at 07:27
  • Issue can be caused by any deallocated instance of `NSString` or `NSDictionary` object. – Midhun MP Feb 26 '14 at 07:28
  • This [link](http://stackoverflow.com/questions/7402171/calayer-release-message-sent-to-deallocated-instance) will help you. – KudoCC Feb 26 '14 at 07:29
  • can you check is it having strong property or not for the class instance in which its crashing, if not can you try by making strong property. – prasad Feb 26 '14 at 07:30
  • @rajesh : It is crashing in main.c file. – Vinay Jain Feb 26 '14 at 07:32
  • @prasad: It is calling the length property on viewcontroller itself. Which i am trying to load. – Vinay Jain Feb 26 '14 at 07:33
  • @VinayJain Exception breakpoint worked? – Rajesh Feb 26 '14 at 07:33
  • @rajesh : I'm trying with putting exception breakpoint. – Vinay Jain Feb 26 '14 at 07:34
  • have you used `performSelector`, `NSTimer` etc to set a `property` ? before setting property try using `[self respondsToSelector:@selector(setLength:)] { // set length here }` – NeverHopeless Feb 26 '14 at 07:34
  • @NeverHopeless : No, i haven't used anything you mentioned. – Vinay Jain Feb 26 '14 at 07:35
  • @rajesh : I tried setting the exception breakpoint, but still didn't get and breakthrough in it. It is crashing the same point in main.c file. I commented the complete code from viewDidAppear and viewDidLoad but still getting the same error. – Vinay Jain Feb 26 '14 at 07:44
  • are you calling length: method anywhere in your application? – Rajesh Feb 26 '14 at 07:57
  • Thanks all, i got an issue. I edit the question and put the resolution there. – Vinay Jain Feb 26 '14 at 08:10

3 Answers3

1

You called -length on something that you thought had a length property, but was actually an instance of your ViewController class.

Post some code, as length can be called implicitly by a variety of methods and classes, and somebody here will likely spot it.

Also, you should go to Debug >> Breakpoints >> CreateExceptionBreakpoint to have the debugger pause execution anytime an exception is thrown. Most of the time this will stop right on the call that is throwing this exception, if not a step or two away or a level or two up the call stack.

ryan cumley
  • 1,901
  • 14
  • 11
  • Thanks. I tried with setting up an exception breakpoint but it didn't helped. I commented out the whole code from viewDidAppear and viewDidLoad and there is nothing executing when the view is loading but still its crashing. – Vinay Jain Feb 26 '14 at 07:57
  • When the exception breakpoint paused your programs execution, what line of code was it on? (It will be highlighted green, usually) – ryan cumley Feb 26 '14 at 08:00
  • Thanks, i got an issue. I edit the question and put the resolution there. – Vinay Jain Feb 26 '14 at 08:09
0

Check your strongs and weaks attributes of your properties in this controller. I think you have any property like weak and it should be strong.

Check Debug Navigator when your app crash, sometimes you can see the trace and this help you

Fran Martin
  • 2,369
  • 22
  • 19
0

Create a symbolic breakpoint in -[NSObject doesNotRecognizeSelector:] as in this answer.

Community
  • 1
  • 1
Simon
  • 25,468
  • 44
  • 152
  • 266