使用不同的数据ios app刷新相同的屏幕

时间:2015-06-15 16:58:01

标签: ios

我正在创建一个简单的应用程序,我们想要向用户提出10个不同的问题和4个选项。

因此,当应用加载时,屏幕有1个问题,4个选项,背景图像和转到按钮。

我已将所有这10个问题与他们的选项和背景图像存储在多维数组中。

当我点击go按钮时,我想刷新同一个屏幕,并希望用他们的选项和背景图像显示下一个问题。

当我回去时。

我是iOS的新手,我应该采取什么方法来实现这个目标?

是否可以使用单个屏幕或我必须制作多个屏幕。

有什么想法吗?有什么建议吗?

1 个答案:

答案 0 :(得分:0)

在您的viewDidLoad等上添加此

[ButtonOne addTarget:self action:@selector(ButtonOne) forControlEvents:UIControlEventTouchUpInside];
[ButtonTwo addTarget:self action:@selector(ButtonTwo) forControlEvents:UIControlEventTouchUpInside];
[ButtonThree addTarget:self action:@selector(ButtonThree) forControlEvents:UIControlEventTouchUpInside];
[ButtonFour addTarget:self action:@selector(ButtonFour) forControlEvents:UIControlEventTouchUpInside];

开始是按钮名称,选择器对于单击按钮时要运行的方法至关重要。

我现在要做的是为每个问题做一个整数。这个整数将决定问题是对还是错。因此,根据问题,整数将被分配给按钮编号,例如如果按钮2为右,则对于该特定问题,整数将被分配给2。我还将使用第二个整数来找出用户所处的问题。

int QuestionNumber;
int Right[11];
Right[1] = *What ever the right button for question 1 is*
....
Right[10] = *What ever the right button for question 10 is*

我现在要为每个按钮创建方法。请注意我只会为其中一个按钮执行此操作,因为其余按钮实际上是相同的。

-(void)ButtonOne
{
    switch (QuestionNumber) {
        case 1:
            if (Right[1] == 1) { //Change the Right[] number depending on question and change the == (1) depending on the button
                NSLog(@"Correct Answer");

                [ButtonOne setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonTwo setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonThree setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonFour setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                Label.text = @"NEXT QUESTION";
                BackGround.image = [UIImage imageNamed:@""];
                QuestionNumber++;
            } else {
                NSLog(@"Got Question wrong");
                //Do whatever you want if question is wrong
            }
            break;
            ....
        case 10:
            if (Right[10] == 1) {
                NSLog(@"Correct Answer");

                [ButtonOne setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonTwo setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonThree setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                [ButtonFour setTitle:@"ANSWER TO OTHER QUESTION" forState:UIControlStateNormal];
                Label.text = @"NEXT QUESTION";
                BackGround.image = [UIImage imageNamed:@""];
            } else {
                NSLog(@"Got Question wrong");
                //Do whatever you want if question is wrong
            }
            break;
        default:
            break;
    }
}

现在正在做的是如果你得到一个正确的问题,它会自动进入下一个问题。如果你想回去,只需添加一个按钮并拥有:QuestionNumber = QuestionNumber -1;当然,再次在该按钮上有一个switch语句,以找出应该显示的内容。

如果您是新手我会建议您观看此YouTube系列,因为它会对您有所帮助。 Here

相关问题