Objective c 通过按UIView按钮更改UIView创建算法

Objective c 通过按UIView按钮更改UIView创建算法,objective-c,algorithm,Objective C,Algorithm,我正在创建一个测验应用程序,我想知道,当你点击ui按钮时,我可以使用int在ui视图之间切换的算法,而不是使用多个if语句。对于多个if语句,代码如下所示: IBAction NextQuestion; { Question++; //QUESTION IS THE int FOR THE ALGORITHM. if (Question==2) { self.view = PlayView2; //PlayView2 is the UIView I'm swi

我正在创建一个测验应用程序,我想知道,当你点击ui按钮时,我可以使用intui视图之间切换的算法,而不是使用多个if语句。对于多个if语句,代码如下所示:

IBAction NextQuestion; {

    Question++; //QUESTION IS THE int FOR THE ALGORITHM.

    if (Question==2) {
        self.view = PlayView2; //PlayView2 is the UIView I'm switching to.
        }

    if (Question==3) {
        self.view = PlayView3; //PlayView3 is the UIView I'm then switching to after the next object/UIButton is pressed.
        }        
等等

iAction连接到多个ui按钮以更改视图。目标是我想通过算法更改UIView而不是多个if语句感谢您的帮助

可能是开关箱

switch(Question) {
    case 2: self.view = PlayView2;
            break;
    case 3: self.view = PlayView3;
            break;
} 
可能是开关箱

switch(Question) {
    case 2: self.view = PlayView2;
            break;
    case 3: self.view = PlayView3;
            break;
} 
myViewsArray=[[NSArray alloc]initWithObjects:PlayView2,PlayView3,…,PlayViewN,nil];
-(UIView*)下一个视图{
如果(问题<[myViewsArray计数])
return[myViewsArray objectAtIndex:Question++];
返回零;
}
myViewsArray=[[NSArray alloc]initWithObjects:playview 2,playview 3,…,playview n,nil];
-(UIView*)下一个视图{
如果(问题<[myViewsArray计数])
return[myViewsArray objectAtIndex:Question++];
返回零;
}

将视图添加到数组中,然后获得一个介于0和array.count-1之间的随机数,怎么样?然后您可以得到您的视图:
view=[array objectAtIndex:randomNumber]。不需要if语句。将视图添加到数组中,并获得一个介于0和array.count-1之间的随机数如何?然后您可以得到您的视图:
view=[array objectAtIndex:randomNumber]。如果需要任何声明,则不需要。