So, I have been doing several tutorials learning how to program iOS, and I have made a few mistakes. I then clean up those mistakes and try something else. I finish up the tutorial as they stated, start up the simulator, and then…. Crash. But how? I did everything the told me to do, their’s works, but mine won’t, what happened?!
Maybe it is from me being so new to interface builder, but so far, it has been kind of hit or miss with error reporting to me. My most recent issue with it, was I was trying to work with a Date Picker so that it would pop up from the bottom when I clicked a textfield, instead of the keyboard. I had to put it into an actionSheet, which is basically a drawer that pops up from the bottom of the screen, similar to how the keyboard shows up. I tried something from a stack overflow post that didn’t work at least for my situation, deleted all of the code, and tried something else. I finished coding that second way of doing it, loaded it up in the simulator, clicked on that textbox, and it crashed with the error: “unrecognized selector sent to instance”, and even with an exception breakpoint, it still pretty much showed up in the main, not very helpful. I tried to put up breakpoints, to stop it before any of my code executed there, but to no avail.
So what was the issue? As part of my first attempt, I had wired up an event for that textbox to an action in my Controller’s .h file. I had deleted that action from the header file, but did not unwire it from Interface Builder. I think it was on touch down, and so when it tried touch down, it looked for that method, couldn’t find it, and crashed. My breakpoints didn’t work because it never even got to them, thanks to this other event.
Now, I can understand it not automatically unwiring it when I delete the action, maybe I wanted to delete it and recreate it with a slightly different prototype, who knows? However, I would expect it to say SOMETHING. Hopefully a compiler error and just not let it compile since it is referencing something that doesn’t exist, but at least a warning, but nothing was there. Again, this may be my lack of experience with IB, but this seems like it would be rather important to show something wired to an action that doesn’t exist.
When recreating this error for this post, I noticed a few things that will help me identify things like this in the future, hopefully. For one, here is more of the error message:
-[CEBViewController notHere:]: unrecognized selector sent to instance
CEBViewController is the name of View Controller, obviously, and “notHere” is the dummy action I made for it, and then deleted in my .h and .m files. In the case of the my original program, the first thing was something like showActionSheet, so it was bit less obvious that it was one that was gone because my new action sheet method was something similar.
Also, I noticed that if I typed the action as a UITextField, this error did not happen, even when it was deleted. Only if I left it’s type as (id), it failed. Something I need to look into more.
Anyway, the moral of the story is, don’t trust IB to find all of your errors for you. It does, and has found other things I tried, deleted, but didn’t entirely clean up, and showed warnings, but apparently it does not every time. It may have a good reason, like that it could have it passed in, or expect it from inheriting or being inherited by something, I don’t know currently. But I do know that I have to be very careful to check everything when I clean up previous attempts to do something.
That’s all for today. Was the problem a newb one? You bet, and that’s I’m here to help others from falling into the same newb trap. Remember, keep your friends close, and your IB even closer.