iphone - 保留随机 View 之间的 UILabel 值

标签 iphone xcode view label uilabel

我正在为 iPhone 制作一个基于 View 的测验应用程序,玩家在回答问题时会在三个不同的 View 之间随机切换。当回答正确时他们会得到+1,当点击错误答案时他们会得到-1。但是回答完问题后,当您进入新的随机 View 时,我需要 UILabel 来显示上一个 View 的分数。我该怎么做?

这是我的代码:

ViewController.h

@interface ViewController : UIViewController {

    IBOutlet UILabel *labelQuestion;
IBOutlet UILabel *labelAnswer1;
IBOutlet UILabel *labelAnswer2;
IBOutlet UILabel *labelAnswer3;
IBOutlet UILabel *labelScore;

int score;    

}

@property (nonatomic, retain) IBOutlet UILabel *labelScore;
@property (nonatomic) int score;


ViewController.m

@synthesize labelScore;
@synthesize score;

-(IBAction)CorrectAnswer; {

    score = score +1;
    labelScore.text = [NSString stringWithFormat:@"%i", score];

}

-(IBAction)WrongAnswer; {

    score = score -1;
    labelScore.text = [NSString stringWithFormat:@"%i", score];

}

最佳答案

使变量分数全局化,即在您的AppDelegate中定义它,您可以在整个应用程序中访问它。

关于iphone - 保留随机 View 之间的 UILabel 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7201666/

相关文章:

java - 自定义 TextView 引发 RuntimeException "Error inflating"

iphone - 如何在 iPhone 中转换时间格式化程序?

iphone - 如何以安全的方式为其他开发人员构建框架或库?

iphone - 如何在UISegementedControl上注册UIControlEventTouchUpInside?

iphone - 私有(private)接口(interface)和多个实现

ios - UIImageView 触摸方法

类不存在

objective-c - UIDatePicker 减慢速度

xcode - 如何在调试中查看 NSString 中的文本

C++ qt基础问题