objective-c - 创建一个通过按下 UIButton 来改变 UIView 的算法

标签 objective-c algorithm

我正在创建一个测验应用程序,我想知道不是使用多个 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/

相关文章:

python - 在二分查找中,计算机如何选择中点以及何时只剩下两个元素

算法设计——用最少的测试人员识别酒窖中的单瓶

algorithm - 需要图形简化算法建议

iphone - CGContextClearRect 带圆圈

记录的sql逻辑压缩

algorithm - 使用线性规划查找 "line of best fit"

objective-c - 如何将 NSData 转换为 NSString?

objective-c - 使用指针作为 NSMutableDictionary 的键的安全方法是什么?

ios - UIDatePicker 自定义可用时间间隔

ios - 单例与核心数据