Take the 2-minute tour ×

I want to create a ChatView exactly like iPhone's texting app (Messages). I'm doing it programmatically and am trying to move the textView up with the keyboard. I want to do this in a function that gets called by UIKeyboardWillShowNotification. Could you help me debug this error?

In ChatViewController.m, I set a listener for UIKeyboardWillShowNotification in the loadView function, and I set self as the textView delegate, but it crashes, saying: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[ChatViewController keyboardWillShow]: unrecognized selector sent to instance

But I define keyboardWillShow in ChatViewController.m Why isn't it finding that function?

Here are the important files:

http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.h http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.m

I commented out the listeners so that it doesn't crash.

Feel free to git clone git@github.com:acani/acani-chat.git


share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Lines 120 and 121 which you have commented out, but I presume are not meant to be since there is no other references to subscribing for notifications, has a problem when you pass the selector. The colon (:) in Objective-C message names are part of the name themselves. Therefore, you are missing a trailing colon to the selector you're passing in. Fix that, and that will get rid of your error.

Also, you should look at making a call to removeObserver: when your view goes away (viewDidUnload).

share|improve this answer
To clarify, you mean @selector(keyboardWillShow:) instead of @selector(keyboardWillShow) (and similarly for s/Show/Hide/). I also highly recommend using [[NSNotificationCenter defaultCenter] removeObserver:self] in dealloc if the class ever registers for notifications. –  tc. Jul 19 '10 at 19:14
If he's registering for the notification in -viewDidLoad then having it only in -dealloc is kinda moot; since he could for instance, go to another view, and come back to this without it being deallocated. -viewDidUnload is a better spot for it. And I'm aware about what I meant, I didn't spoon feed him the answer because I felt the explanation was better. –  jer Jul 19 '10 at 19:39
Thanks guys! That fixed it! duh... sleep is good. –  MattDiPasquale Jul 23 '10 at 6:20
add comment

Your Answer


