关于textfield的使用
来源:互联网 发布:赛诺数据是什么 编辑:程序博客网 时间:2024/05/17 09:32
I took the example that Jack provided and actually created a working project, this was done using the Cocos2D 0.7.1 XCode Template, and then just editting the *AppDelegate.m/.h files, which are provided below in there entirety. I also modified some of what Jack said, because I feel that creating the UITextField in the appDidFinishLoading would utilize a bit too much memory, especially if the text field is not used all the time ... this solution creates the text field only when it is needed, the sample draws an empty Cocos2D Layer scene, and on screen touch, it displays the text field for you to start entering text into. It will spit out the result of what you entered to the Console - you can pass this to whatever is necessary in your own code.
the .h
#import <UIKit/UIKit.h>
#import "cocos2d.h"
@interface MYSCENE :Layer<UITextFieldDelegate>
{
UITextField*myText;
}
-(void)specificStartLevel;
@end
@interface textFieldTestAppDelegate :NSObject<UIAccelerometerDelegate,UIAlertViewDelegate,UITextFieldDelegate,UIApplicationDelegate>
{
UIWindow*window;
}
@end
and then the .m
#import "textFieldTestAppDelegate.h"
@implementation MYSCENE
-(id) init
{
self =[super init];
isTouchEnabled = YES;
return self;
}
-(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent*)event {
[self specifyStartLevel];
return kEventHandled;
}
-(void)specifyStartLevel {
myText =[[UITextField alloc] initWithFrame:CGRectMake(60,165,200,90)];
[myText setDelegate:self];
[myText setText:@""];
[myText setTextColor:[UIColor colorWithRed:255 green:255 blue:255 alpha:1.0]];
[[[[Director sharedDirector] openGLView] window] addSubview:myText];
[myText becomeFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField {
[myText resignFirstResponder];
return YES;
}
-(void)textFieldDidEndEditing:(UITextField*)textField {
if(textField == myText){
[myText endEditing:YES];
[myText removeFromSuperview];
NSString*result = myText.text;
NSLog([NSString stringWithFormat:@"entered: %@", result]);
}else{
NSLog(@"textField did not match myText");
}
}
-(void) dealloc
{
[super dealloc];
}
@end
@implementation textFieldTestAppDelegate
-(void)applicationDidFinishLaunching:(UIApplication*)application
{
window =[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[[Director sharedDirector] setDisplayFPS:YES];
[[Director sharedDirector] attachInWindow:window];
Scene*scene =[Scene node];
[scene addChild:[MYSCENE node]];
[window makeKeyAndVisible];
[[Director sharedDirector] runWithScene: scene];
}
-(void)dealloc
{
[super dealloc];
}
-(void) applicationWillResignActive:(UIApplication*)application
{
[[Director sharedDirector] pause];
}
-(void) applicationDidBecomeActive:(UIApplication*)application
{
[[Director sharedDirector] resume];
}
-(void)applicationDidReceiveMemoryWarning:(UIApplication*)application
{
[[TextureMgr sharedTextureMgr] removeAllTextures];
}
@end
- 关于textfield的使用
- 关于textView,textField及delegate的使用
- 关于获取textField的textFormat的使用总结
- as3:TextField的使用
- TextField的简单使用
- TextField的使用
- 关于textfield的一些细节
- AS3 TextField 类的使用
- textView、textField ReturnKey 的使用
- Cocos2d-x TextField的使用
- extjs 关于 textfield 校验的提示
- 关于textView,textField及delegate的应用
- 关于textField的功能收集汇总
- 关于在extjs中使用column布局,不能显示textfield的标签(fieldLabel)解决方法
- 关于在extjs中使用column布局,不能显示textfield的标签(fieldLabel)解决方法
- TextField类中embedFonts属性的使用
- textfield的使用 想不会都难
- TextField 与FTE的使用情景
- Km Kcat Kcat/Km
- Web性能压力测试工具之WebBench详解
- 动态规划解决01背包问题
- coco2dx开发的小总结篇章 不断更新
- 程序员真的很懒
- 关于textfield的使用
- Spring Security3.1 最新配置实例
- 6个变态的C语言Hello World程序
- thinkphp中验证码的使用
- :[转贴]变态级JAVA程序员面试32问(附答案
- 【转】tableview详解
- 给JavaScript初学者的24条最佳实践
- 关于java的main函数
- 我的java学习笔记