• iOS中switchcase的优化用法


    之前使用switch-case的时候一直无法使用声明语句,只能使用调用函数的语句,今天看到了高手使用

    其实也就是加一个 { } 即可。

    来自于ATMHud

    - (void)advancedHudActionForRow:(NSUInteger)row {
        [hud setBlockTouches:YES];
        switch (row) {
            case 0:
                [hud setCaption:@"This HUD will auto-hide in 2 seconds."];
                [hud show];
                [hud hideAfter:2.0];
                break;
                
            case 1:
                [hud setCaption:@"This HUD will update in 2 seconds."];
                [hud setActivity:YES];
                [hud show];
                [self performSelector:@selector(updateHud) withObject:nil afterDelay:2.0];
                break;
                
            case 2: {
                NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
                [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
                [hud setCaption:@"Performing operation..."];
                [hud setProgress:0.08];
                [hud show];
                break;
            }
                
            case 3: {
                ATMHudQueueItem *item = [[ATMHudQueueItem alloc] init];
                item.caption = @"Display #1";
                item.image = nil;
                item.accessoryPosition = ATMHudAccessoryPositionBottom;
                item.showActivity = NO;
                [hud addQueueItem:item];
                [item release];
                
                item = [[ATMHudQueueItem alloc] init];
                item.caption = @"Display #2";
                item.image = nil;
                item.accessoryPosition = ATMHudAccessoryPositionRight;
                item.showActivity = YES;
                [hud addQueueItem:item];
                [item release];
                
                item = [[ATMHudQueueItem alloc] init];
                item.caption = @"Display #3";
                item.image = [UIImage imageNamed:@"19-check"];
                item.accessoryPosition = ATMHudAccessoryPositionBottom;
                item.showActivity = NO;
                [hud addQueueItem:item];
                [item release];
                
                [hud startQueue];
                [self performSelector:@selector(showNextDisplayInQueue) withObject:nil afterDelay:2];
                break;
            }
        }
    }

    其实也就是添加了大括号

    case 2: {
                NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
                [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
                [hud setCaption:@"Performing operation..."];
                [hud setProgress:0.08];
                [hud show];
                break;
            }
  • 相关阅读:
    Reading papers_2(与GMM相关,ing...)
    Matlab DIP(瓦)ch11表示与描述练习
    HMM学习笔记_1(从一个实例中学习DTW算法)
    Matlab DIP(瓦)ch10图像分割练习
    前景检测算法_2(帧差法1)
    目标跟踪学习笔记_3(particle filter初探2)
    基础学习笔记之opencv(2):haartraining前将统一图片尺寸方法
    Reading papers_5(与human activity analysis综述相关,ing...)
    总结系列_4(C++知识学习,续...)
    HMM学习笔记_2(从一个实例中学习HMM前向算法)
  • 原文地址:https://www.cnblogs.com/easonoutlook/p/2642011.html
Copyright © 2020-2023  润新知