0

I have a calendar with events inside, and I want the user to be able to add notes to every event. I do this through a UITextView, but the app crashes some times after writing the first letter saying

-[__NSArrayM text]: Unrecognized selector sent to instance

The weird part is, that I use no code whatsoever to track the input, until the user hits a "Done" button. I get the same error when using UITextField as well, and I can't find out why does the error sometimes occur, and sometimes it works all fine.

Denis Balko
  • 1,566
  • 2
  • 15
  • 30
  • Well, `NSArray` doesn't have a `text` method. What does the backtrace say? – Carl Norum Apr 20 '13 at 17:30
  • 1
    It isn't called without reason, it's called because somewhere you have passed the wrong object or over released an object (so another object is receiving a method call not intended for it). You need to find out which and where. – Wain Apr 20 '13 at 17:33
  • Well the thing is that I am not calling it. As for the error, I don't have it here with me as it occurs only from time to time and I just can't get to reproduce it right now, but it is pretty much only that piece of code I put in my question – Denis Balko Apr 20 '13 at 17:33
  • > -[__NSArrayM text]: unrecognized selector sent to instance 0xaba93d0 – Denis Balko Apr 20 '13 at 17:34
  • > *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM text]: unrecognized selector sent to instance 0xaba93d0' – Denis Balko Apr 20 '13 at 17:35
  • 1
    Consider turning on zombies: http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4 – Wain Apr 20 '13 at 17:36

1 Answers1

2

You have a dangling reference. You had an object that responded to the text message. You deallocated it but you still have a reference to it somewhere. You reused the memory of that deallocated object to create an NSMutableArray, then sent the text message through the dangling reference.

Run your app under the Zombies instrument to help track down the bug.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • zombies will give you the class... you may also have to go through the whole malloc logging rigmarole to see what the whole story is. – Grady Player Apr 20 '13 at 17:40
  • Instruments takes care of malloc logging for you. [It can show you the call stacks of every `retain`, `release`, and `autorelease` message, and the call stacks of the object's `alloc` and `dealloc`.](http://stackoverflow.com/a/14891837/77567) – rob mayoff Apr 20 '13 at 17:51