Fixed bugs

This commit is contained in:
CaiWenzhi 2013-12-30 14:40:49 +08:00
parent a788d7cd27
commit e5b0bbad74
3 changed files with 25 additions and 18 deletions

View File

@ -326,10 +326,21 @@ void TextField::setTouchSize(const Size &size)
void TextField::setText(const std::string& text) void TextField::setText(const std::string& text)
{ {
if (text.size()==0) std::string strText(text);
return; if (isMaxLengthEnabled())
{
_textFieldRenderer->setString(text); strText = strText.substr(0, getMaxLength());
}
const char* content = strText.c_str();
if (isPasswordEnabled())
{
_textFieldRenderer->setPasswordText(content);
_textFieldRenderer->insertText(content, strlen(content));
}
else
{
_textFieldRenderer->setString(content);
}
textfieldRendererScaleChangedWithSize(); textfieldRendererScaleChangedWithSize();
} }

View File

@ -70,7 +70,7 @@ bool UIListViewTest_Vertical::init()
(backgroundSize.width - listView->getSize().width) / 2.0f, (backgroundSize.width - listView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f + (widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - listView->getSize().height) / 2.0f)); (backgroundSize.height - listView->getSize().height) / 2.0f));
listView->addEventListenerScrollView(this, scrollvieweventselector(UIListViewTest_Vertical::selectedItemEvent)); listView->addEventListenerListView(this, listvieweventselector(UIListViewTest_Vertical::selectedItemEvent));
_uiLayer->addChild(listView); _uiLayer->addChild(listView);
@ -167,22 +167,20 @@ bool UIListViewTest_Vertical::init()
return false; return false;
} }
void UIListViewTest_Vertical::selectedItemEvent(Object *pSender, ScrollviewEventType type) void UIListViewTest_Vertical::selectedItemEvent(Object *pSender, ListViewEventType type)
{ {
/*
switch (type) switch (type)
{ {
case SCROLLVIEW_EVENT_SELECT_CHILD: case LISTVIEW_ONSELECTEDITEM:
{ {
ListView* listView = static_cast<ListView*>(pSender); ListView* listView = static_cast<ListView*>(pSender);
CCLOG("select child index = %d", listView->getSelectedChildIndex()); CCLOG("select child index = %ld", listView->getCurSelectedIndex());
} }
break; break;
default: default:
break; break;
} }
*/
} }
// UIListViewTest_Horizontal // UIListViewTest_Horizontal
@ -245,7 +243,7 @@ bool UIListViewTest_Horizontal::init()
(backgroundSize.width - listView->getSize().width) / 2.0f, (backgroundSize.width - listView->getSize().width) / 2.0f,
(widgetSize.height - backgroundSize.height) / 2.0f + (widgetSize.height - backgroundSize.height) / 2.0f +
(backgroundSize.height - listView->getSize().height) / 2.0f)); (backgroundSize.height - listView->getSize().height) / 2.0f));
listView->addEventListenerScrollView(this, scrollvieweventselector(UIListViewTest_Horizontal::selectedItemEvent)); listView->addEventListenerListView(this, listvieweventselector(UIListViewTest_Horizontal::selectedItemEvent));
_uiLayer->addChild(listView); _uiLayer->addChild(listView);
@ -342,20 +340,18 @@ bool UIListViewTest_Horizontal::init()
return false; return false;
} }
void UIListViewTest_Horizontal::selectedItemEvent(Object *pSender, ScrollviewEventType type) void UIListViewTest_Horizontal::selectedItemEvent(Object *pSender, ListViewEventType type)
{ {
/*
switch (type) switch (type)
{ {
case SCROLLVIEW_EVENT_SELECT_CHILD: case LISTVIEW_ONSELECTEDITEM:
{ {
ListView* listView = static_cast<ListView*>(pSender); ListView* listView = static_cast<ListView*>(pSender);
CCLOG("select child index = %d", listView->getSelectedChildIndex()); CCLOG("select child index = %ld", listView->getCurSelectedIndex());
} }
break; break;
default: default:
break; break;
} }
*/
} }

View File

@ -33,7 +33,7 @@ public:
UIListViewTest_Vertical(); UIListViewTest_Vertical();
~UIListViewTest_Vertical(); ~UIListViewTest_Vertical();
bool init(); bool init();
void selectedItemEvent(Object* pSender, ScrollviewEventType type); void selectedItemEvent(Object* pSender, ListViewEventType type);
protected: protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical) UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
@ -48,7 +48,7 @@ public:
UIListViewTest_Horizontal(); UIListViewTest_Horizontal();
~UIListViewTest_Horizontal(); ~UIListViewTest_Horizontal();
bool init(); bool init();
void selectedItemEvent(Object* pSender, ScrollviewEventType type); void selectedItemEvent(Object* pSender, ListViewEventType type);
protected: protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal) UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)