我正在创建一个测验应用程序,我想知道不是使用多个 if 语句,我可以制作一个算法,使用 int 在 之间交替>UIViews 当您点击一个 UIButton 时。使用多个 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.
}
等等……
IBAction 连接到多个 UIButtons 以更改 View 。我的目标是我想通过算法更改 UIView 而不是多个 if 语句 感谢您的帮助!
最佳答案
myViewsArray = [[NSArray alloc] initWithObjects: PlayView2, PlayView3, ..., PlayViewN, nil];
-(UIView*) nextView {
if( Question < [myViewsArray count] )
return [myViewsArray objectAtIndex: Question++];
return nil;
}
关于objective-c - 创建一个通过按下 UIButton 来改变 UIView 的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9656427/