2011-05-19 33 views
0

我有一些按鈕的標籤已經設置爲1到10.現在如果用戶點擊按鈕,標籤值應該在下一個屏幕上發送/ nib的標籤。在按鈕上使用標籤並在下一個視圖中傳遞標籤值label-iphone

-(IBAction) gotoGameScreen:(id)sender 
{ 
    [self playAudio];  
UIButton *btn=(UIButton *)sender;  
NSLog(@"Use Selected Level=%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]; 
} 

有什麼建議嗎? 感謝

回答

0

使用GameScreen一個整數,並定義屬性和合成它,並通過本按鈕標籤的值設置到下...

-(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]; 

} 
0

這不會工作。你應該做的是創造一個整數,如

int iButtonTag;  

設置其屬性爲

@property(nonatomic,assign) int iButtonTag; 

和合成它。

將此int用於paas按鈕的標記上。這個包含int的按鈕標籤將在下一個viewController中使用。