using tag on a button and passing tag value in next view label-iphone
i am having some buttons whose tags have been set from 1 to 10.Now if user clicks on the buttons, the tag value should be send in next screen/nib's label.
-(IBAction) gotoGameScreen:(id)sender
{
[self playAudio];
UIButton *btn=(UIButton *)sender;
NSLog(@"Use Selected Lev开发者_Go百科el=%d",btn.tag);//here i am getting the tag value as 1.
GameScreen *gameScreen = [[GameScreen alloc] initWithNibName:@"GameScreen" bundle:nil];
[self.navigationController pushViewController:gameScreen animated:YES];
[gameScreen release];
}
any suggestion? Thanks
use an integer in GameScreen and define property and synthesize it and pass value of present button tag to next ...
-(IBAction) gotoGameScreen:(id)sender
{
[self playAudio];
UIButton *btn=(UIButton *)sender;
NSLog(@"Use Selected Level=%d",btn.tag);
GameScreen *gameScreen = [[GameScreen alloc] initWithNibName:@"GameScreen" bundle:nil];
gameScreen.tagValue=btn.tag;
[self.navigationController pushViewController:gameScreen animated:YES];
[gameScreen release];
}
This wont work. What you should do is to create an integer eg
int iButtonTag;
Set its property as
@property(nonatomic,assign) int iButtonTag;
and synthesize it.
Use this int to paas on the tag of button. This int containing button tag will be used in next viewController.
精彩评论