how to use the CCIMEDelegate????

I’ve implemented from the class KeyboardNotificationLayer (like the example in the test project)

class MyLayer : public KeyboardNotificationLayer,public CCTextFieldDelegate { KeyboardNotificationLayer * m_pNotificationLayer; public: virtual void onEnter(); virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent); virtual void onClickTrackNode(bool bClicked,CCNode* node); virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen); };

And in *MyLayer::onEnter()*, i have set three CCTextFieldTTF as follow:
@
TextFieldTTF1 = CCTextFieldTTF::textFieldWithPlaceHolder(…);
TextFieldTTF2 = CCTextFieldTTF::textFieldWithPlaceHolder(…);
TextFieldTTF3 = CCTextFieldTTF::textFieldWithPlaceHolder(…);
@

I set as follow:
@
TextFieldTTF1~~>setDelegate;
TextFieldTTF2~~>setDelegate(this);
TextFieldTTF3->setDelegate(this);
@

but touch the TextfieldTTF, there’s no keyboard appear, and can’t insert the char into the textfield,

in the other way , when I don’t set Delegate to above three TextFieldTTFs(TextFieldTTF1,TextFieldTTF2,TextFieldTTF3), the keyboard is work well when touching the textfield ,and inserting chars from typing on keyboard into textfield…

Is there any thing wrong to use???

thanks for response……

best regards,

Hi,jack Lin
I have modified TextInputTest.h and TextInputTest.cpp to meet your needs. Please download the attach files and replace them to have a try.
What I modified is ‘TextFieldTTFActionTest’ test demo. I have tested it on android and win32. And it works fine.

Thanks your reply , first !

Your modification i know, but the problem what I face is:

I just create a new scene , and create a new layer named MyLayer on this scene ( declared as follow )

class KeyboardNotificationLayer : public CCLayer, public CCIMEDelegate
{
public:
    KeyboardNotificationLayer();
    virtual void onClickTrackNode(bool bClicked,CCNode* node ) = 0;
    virtual void registerWithTouchDispatcher();
    virtual void keyboardWillShow(CCIMEKeyboardNotificationInfo& info);
    virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
protected:
    CCNode * m_pTrackNode;
    CCPoint  m_beginPos;
};

class *MyLayer* : public KeyboardNotificationLayer,public CCTextFieldDelegate {
   KeyboardNotificationLayer * m_pNotificationLayer;
public:
   virtual void onEnter();
   virtual void ccTouchEnded(CCTouch pTouch, CCEvent *pEvent);
   virtual void onClickTrackNode(bool bClicked,CCNode node);
   virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen); 
};

And I set delegate() in the MyLayer::onEnter*
<pre>
TextFieldTTF1 = CCTextFieldTTF::textFieldWithPlaceHolder;
TextFieldTTF2 = CCTextFieldTTF::textFieldWithPlaceHolder;
TextFieldTTF3 = CCTextFieldTTF::textFieldWithPlaceHolder;
TextFieldTTF1~~>setDelegate;
TextFieldTTF2~~>setDelegate;
TextFieldTTF3~~>setDelegate;
</pre>
It doesn’t work! there is no keyborad,and can’t insert words into textField!
But if I don’t setDelegate of these three TextFieldTTF , there is a keyboard and i can type into textfield,
But in this way, it doesn’t run the virtual function MyLayer::onTextFieldInsertText to catch the words what i type on the keyboard.
<pre>
TextFieldTTF1 = CCTextFieldTTF::textFieldWithPlaceHolder;
TextFieldTTF2 = CCTextFieldTTF::textFieldWithPlaceHolder;
TextFieldTTF3 = CCTextFieldTTF::textFieldWithPlaceHolder;
//TextFieldTTF1~~>setDelegate;
//TextFieldTTF2~~>setDelegate;
//TextFieldTTF3~~>setDelegate;
</pre>
In the tests project, there is one layer to add another KeyboardNotificationLayer,
But in my pratice, I set the touch layer and KeyboardNotificationLayer in the same layer , if I don’t set delegate,keyboard can
appear and i can insert words into textfield,but can’t run the function
MyLayer::onTextFieldInsertText().
It doesn’t work when i set three textfield
setDelegate()* ,

I don’t know why, i just wanna to capture the words what i type on the keyboard in the virtual function *onTextFieldInsertText()*, but i can’t do

it well

class MyLayer : public KeyboardNotificationLayer,public CCTextFieldDelegate
class TextFieldTTFActionTest : public KeyboardNotificationLayer, public CCTextFieldDelegate
?? what’s the difference? I don’t quite understand you.
I want to know the impletment of your MyLayer::ccTouchEnded.

My touchEnded is declare as follow:

void LoginLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
    CCPoint endPos = pTouch->locationInView(pTouch->view());    
    endPos = CCDirector::sharedDirector()->convertToGL(endPos);

    float delta = 5.0f;
    if (::abs(endPos.x - m_beginPos.x) > delta || ::abs(endPos.y - m_beginPos.y) > delta)
    {
        m_beginPos.x = m_beginPos.y = -1;
        return;
    }
    CCRect rect;
    CCPoint point = convertTouchToNodeSpaceAR(pTouch);

    for( i = 0; i < 3; i++ )
    {
    rect = getRect(input[i]); // input[i] is the three (CCNode*) TextFieldTTF that i save while creating TextFieldTTF 
    Hit = CCRect::CCRectContainsPoint(rect, point);
    if( Hit )   NowInputMaxChar = MaxCharInput[i];  
    onClickTrackNode( Hit, input[i] );
    }
}

The difference is:

I only use only one layer named MyLayer to control touch, KeyboardNotificationLayer , and all of displays…

In the tests project, +it has two layers,a ContainerLayer layer ( TextInputTest ) adds a new layer( named TextFieldTTFActionTest+ that

derived from KeyboardNotificationLayer and CCLayer ) to control KeyboardNotificationLayer.

I don’t know what problem could let me failed.

Can you try the way that I use?
just create a scene and create one layer, on this layer has one textfield to insert
words.
PS. I try to debug that, and when I set textfield->delegate,in the function onClickTrackNode, CCIMEDelegate::attachWithIME return false;
but when I don’t set delegate, CCIMEDelegate::attachWithIME return true,
Is anything wrong???

jack Lin wrote:

My touchEnded is declare as follow:
[…]
>
The difference is:
>
I only use only one layer named MyLayer to control touch, KeyboardNotificationLayer , and all of displays…
>
In the tests project, +it has two layers,a ContainerLayer layer ( TextInputTest ) adds a new layer( named TextFieldTTFActionTest+ that
>
derived from KeyboardNotificationLayer and CCLayer ) to control KeyboardNotificationLayer.
>
I don’t know what problem could let me failed.
>
Can you try the way that I use?
>
just create a scene and create one layer, on this layer has one textfield to insert
>
words.
>
PS. I try to debug that, and when I set textfield->delegate,in the function onClickTrackNode, CCIMEDelegate::attachWithIME return false;
>
but when I don’t set delegate, CCIMEDelegate::attachWithIME return true,
>
Is anything wrong???

Hi, could you please send the demo to me by email.Thanks.

Hi! James,

I know what i make a mistake….

In MyLayer declaration , I also declare virtual function as follow:

In MyLayer.h

   virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);
   virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);

In MyLayer.cpp

   void MyLayer::onTextFieldAttachWithIME(CCTextFieldTTF * pSender)
  {
     return true;
  }

  void MyLayer::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)
  {
     return true;
  }

But if I don’t declare these two virtual function, it works fine !

What the problem is ???

i mail the test1 demo project to you, you can try it

thanks for your Reply, again

Best Regards,

It’s ok.:slight_smile:

May I ask you what the reasons taht I can’t do it fine???

According to the tests project, it can also declare the virtual function onTextFieldAttachWithIME() and onTextFieldDetachWithIME(),

But in my code, I can’t ,

Don’t know why……

Hi, the two functions below should return false, your code return true.

bool NextLayer::onTextFieldAttachWithIME(CCTextFieldTTF * pSender)
{
return false;
}

bool NextLayer::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)
{
return false;
}

onTextFieldDeleteBackward should also return false.:slight_smile:

Dear James:

Thanks a lot

I make a mistake to skip the returned value from two functions…

Thanks for Reply)

Best Regards,