iphone - Best way to pass variables between views -
iphone - Best way to pass variables between views -
i new xcode & objective-c (having come php) have started play around , finding hard pass variables between views have far:
game_info.h
#import <uikit/uikit.h> @interface game_info : uiviewcontroller { iboutlet uitextfield *groupname; iboutlet uisegmentedcontrol *gametype; } @property (nonatomic,retain) iboutlet uitextfield *groupname; - (ibaction) gametypepicker; - (ibaction) keyboardhide; - (ibaction) backbtn; - (ibaction) nextbtn; @end game_info.m
#import "i_dare_youviewcontroller.h" #import "game_info.h" #import "game_tdor.h" @implementation game_info @synthesize groupname; // next button -(ibaction) nextbtn{ if ([groupname.text length] == 0) { // alert uialertview *alert = [[uialertview alloc] initwithtitle:@"group name" message:@"please come in grouping name" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil ]; [alert show]; [alert release]; }else if([groupname.text length] < 3){ // alert uialertview *alert = [[uialertview alloc] initwithtitle:@"group name" message:@"please come in name longer 3 characters" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil ]; [alert show]; [alert release]; }else{ game_tdor *screen = [[game_tdor alloc] initwithnibname:nil bundle:nil]; screen.modaltransitionstyle = uimodaltransitionstylecrossdissolve; [self presentmodalviewcontroller:screen animated:yes]; [screen release]; game_tdor *screen1 = [[game_tdor alloc] initwithnibname:nil bundle:nil]; nslog(@"game_info: %@",self.groupname.text); screen1.groupnametext = self.groupname.text; [self presentmodalviewcontroller:screen1 animated:yes]; [screen1 release]; } } then in view / .h / .m file trying 'groupname' property.
game_tdor.m
#import "i_dare_youviewcontroller.h" #import "game_info.h" #import "game_tdor.h" @implementation game_tdor @synthesize groupnametext,testlbl; - (void)viewdidload { nslog(@"game_tdor: %@",self.groupnametext); nsstring *msg = [[nsstring alloc] initwithformat:@"hello, %@",[self.groupnametext capitalizedstring]]; [testlbl settext:msg]; [msg release]; [super viewdidload]; // additional setup after loading view nib. } so trying on first view page (game_info) there input text box , im trying pass label on view page (game_tdor)
this comes out in nslog (note sec page (game_tdor) comes out first in log.
2011-07-17 00:25:34.765 dare you[3941:207] game_tdor: (null) 2011-07-17 00:25:34.774 dare you[3941:207] game_info: name problem solved:
on next button needed add together variable before moved page (not other way around - silly noobish thing do...)
game_tdor *screen1 = [[game_tdor alloc] initwithnibname:nil bundle:nil]; nslog(@"game_info: %@",self.groupname.text); screen1.groupnametext = self.groupname.text; [self presentmodalviewcontroller:screen1 animated:yes]; [screen1 release]; game_tdor *screen = [[game_tdor alloc] initwithnibname:nil bundle:nil]; screen.modaltransitionstyle = uimodaltransitionstylecrossdissolve; [self presentmodalviewcontroller:screen animated:yes]; [screen release];
if need pass value of groupname.text game_info view controller game_tdor view controller, presented modally former, can declare property in game_tdor hold value:
1) declare nsstring property in game_tdor @interface block:
@property (nonatomic,copy) nsstring *groupnametext; (remember synthesize or implement accessor methods in implementation block)
2) in nextbtn action, after initialize game_tdor instance, set property:
game_tdor *screen = [[game_tdor alloc] init...]; screen.groupnametext = self.groupname.text; iphone objective-c xcode
Comments
Post a Comment