我花了一個月試圖將我的int傳遞給一個新的視圖。我的int被稱爲score,並連接到一個名爲scorelab的標籤。用戶增加分數,一旦他們用完時間遊戲將視圖切換到屏幕上的遊戲,並且我希望用戶分數在標籤中的屏幕上顯示在遊戲上。遊戲控制器被稱爲GamePlayViewController
,並且控制器被給予爲GameDidEndViewController
。我厭倦了試圖讓這個工作。我已經看過每一個可能的教程,但似乎沒有任何工作適合我的情況。請幫助我,我會很感激,這是我需要完成的最後一部分遊戲。先謝謝你!將一個int傳遞給一個新的ViewController
對不起這裏是代碼:
GamePlayViewController.h
#import "GameDidEndViewController.h"
int score;
IBOutlet UILabel *scorelab;
GamePlayViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"GameOver"])
{
GameDidEndViewController *vc = [segue destinationViewController];
[vc setscore2: score];
}
}
GameDidEndViewController.h
#import "GamePlayViewController.h"
IBOutlet UILabel *scorelab2;
int score2;
}
@property (nonatomic , assign) int score2;
@property (nonatomic , assign) UILabel *scorelab2;
耍花招idEndViewController.m
@synthesize score2 , scorelab2;
-(void)viewWillAppear:(BOOL)animated {
scorelab2.text = [NSString stringWithFormat: @"%d", score2];
[super viewWillAppear: animated];
}
你有什麼試過?如果你一直在嘗試一個月,那肯定意味着你有一些不起作用的代碼。我們在這裏告訴你爲什麼它不起作用,不是爲你做。 –