CCTextFieldDelegate::onTextFieldInsertText() not being overriden

I’ve got my CCLayer which derives from CCTextFieldDelegate so that I can do some custom coding whenever a character is entered using the virtual keyboard.

class MyLayer: public CCLayer, public CCTextFieldDelegate
{

virtual bool onTextFieldInsertText(cocos2d::CCTextFieldTTF* pSender, const char* text, int nLen) { … }
};

But the method is not invoked.

P.S., this is the main layer ( i.e. replaceScene(MyLayer); )

Basically I am trying to implement a password label by using the onTextFieldInsertText() method.

To answer my own question.

You need to set the delegate of the CCTextfield: mytextfield->setDelegate(myLayer);