开发者

How to get current value of UITextField in cocos2d 0.8.2?

开发者 https://www.devze.com 2022-12-21 09:04 出处:网络
Hi all I am using cocos2d开发者_JAVA百科 0.8.2 for my new game. I have added a UITextField in my game and on click of a button (this button is actually a sprite i m using ccTouchesEnded! ) i save text

Hi all I am using cocos2d开发者_JAVA百科 0.8.2 for my new game. I have added a UITextField in my game and on click of a button (this button is actually a sprite i m using ccTouchesEnded! ) i save text field's value in database, but whenever i access the value i am getting nil. if i initialize the textfield value by some string, it always give me only that value. i.e.

[txtField setText:@"Enter Your Name"];

when i access the value of txtField on a click of button it always give me "Enter Your Name". Although the value is changing when i type in textField, but its not returning me the new value.

is this a issue with cocos2d 0.8.2 or i am missing something?


You don't save the entered text. You just set @"Enter your Name" as default text, that is displayed in the cell. You should have a look at the UITextFieldDelegate methods. You have to overwrite the method didEndEditing, that is called after your editing or typing in text has ended, and implement there a line that saves the current value. Here you can use something like this:

NSString *containerForTextFieldValue = textField.text;
0

精彩评论

暂无评论...
验证码 换一张
取 消