switch...case 基本语法格式:
switch (表达式){
case 值1 : 语句1 break; case 值2 : 语句2 break; ... default : 语句n break; } 从表达式值等于某个case语句后的值开始,它下方的所有语句都会一直运行,直到遇到一个break为止。假如任何一个case语句的值都不等于表达式的值,就运行可选标签default之下的语句。
在oc中的应用如下:
switch (status.user.verified_type) {
case -1:
self.verified_type_image.image = nil;
break;
case 0:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_vip"];
break;
case 2:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 3:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 5:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_enterprise_vip"];
break;
case 220:
self.verified_type_image.image = [UIImage imageNamed:@"avatar_grassroot"];
break;
default:
self.verified_type_image.image = nil;
break;
}