views:

321

answers:

2

Hi. I'm have a TextViewCell with a text field that that I'm using in a tableview. I need the current view controller to be the delegate. Nothing worked and in my searches I found the code below, which I implemented in my initWithNib method:

     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
 [nc addObserver:self selector:@selector(textDidEndEditing:) name:NSTextDidEndEditingNotification object:tableView];

But i'm getting the error NSTextDidEndEditingNotification Undeclared (first use in function)

Why am I getting that error? How do I fix that?

Thanks

+2  A: 

The notification you're using belongs to NSTextField, which belongs to Cocoa Touch's big brother, the desktop Cocoa. What you want is UITextFieldTextDidEndEditingNotification which is the notification sent out by UITextField, the text control on the iPhone. The docs are here.

HTH.

EightyEight
duhhh....I should have caught that. Thanks
Xcoder
+1  A: 

Hmmm...I don't think you're going about this the right way. First of all, you should have your view controller adopt the UITextFieldDelegate protocol in your header file.

@interface MyViewController : UIViewController <UITextFieldDelegate>

Next, you want to want to use the following method in your implementation file:

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    //My text field has been edited!
}

If you are building your application with Interface Builder, you can set your view controller as the delegate by dragging a connection from the delegate outlet to your File's Owner in your XIB.

Otherwise, you will just use the following code:

myTextField.delegate = self;

That should do it!

Reed Olsen
Yep, I tried that at first and had problem because of the custom cell and finally went back to that. However, I'm still curious about why the notification wouldn't have worked and it gave me that error.
Xcoder