Hi All, I am having a problem in placing data(textField text) from one scene to another scene. I'm attaching my source code with this mail. Please help me if anything wrong in my code.
//
// PlayerSettingsAppDelegate.m
// PlayerSettings
//
//
//
#import "PlayerSettingsAppDelegate.h"
#import "TestScene.h"
NSString *result;
@implementation MYSCENE
-(id) init
{
[super init];
id layer = [ColorLayer layerWithColor: 0x2266FFff];
[self add:layer z:0];
[MenuItemFont setFontSize:15];
[MenuItemFont setFontName:@"Helvetica"];
MenuItem *backMenu = [MenuItemFont itemFromString:@"Back" target:self selector:@selector(menuBack:)]
;
Menu *menu = [Menu menuWithItems:backMenu,nil];
[menu alignItemsVertically];
[self add:menu];
/*Text field creation*/
myTextField = [[UITextField alloc]initWithFrame:CGRectMake(60, 165, 100, 10)];
myTextField.placeholder=@"<Enter text>";
[myTextField setDelegate:self];
[window addSubview:myTextField];
return self;
}
-(void)menuBack:(id)sender{
NSLog(@"Back");
TestScene *ts = [TestScene node];
[[Director sharedDirector]replaceScene:ts];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
if(textField==myTextField){
[myTextField endEditing:YES];
result = myTextField.text;
[label setString:result];
[myTextField removeFromSuperview];
}
}
-(void) dealloc
{
[super dealloc];
}
@end
@implementation MenuLayer
-(id)init {
self = [super init];
return self;
}
@end
@implementation PlayerSettingsAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// NEW: Init the window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
//[window setMultipleTouchEnabled:YES];
//[[Director sharedDirector] setLandscape: YES];
[[Director sharedDirector] setDisplayFPS:YES];
[[Director sharedDirector] attachInWindow:window];
Scene *scene = [Scene node];
[scene add: [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
-------------------------------------------------------------------------
//
// TestScene.m
// PlayerSettings
//
//
//
#import "TestScene.h"
#import "cocos2d.h"
#import "PlayerSettingsAppDelegate.h"
UITextField *levelEntryTextField;
@implementation TestScene
-(id)init{
[super init];
Sprite *bg = [Sprite spriteWithFile:@"image1.jpg"];
[bg setPosition:cpv(160,240)];
[self add:bg z:0];
label = [Label labelWithString:@"result" fontName:@"Helvetica" fontSize:20.0];
label.position = cpv(100,100);
[self add:label z:1];
return self;
}
@end