我试图简化开关语句,它需要大量空间和时间来编写。在代码中,你会明白的。如果没有,我会稍后解释。简化开关语句(Objective-C)
// When row is selected
- (void)pickerView:(UIPickerView *)pickerTimer didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (row) {
case 0:
NSLog(@"It obviously worked.0");
break;
case 1:
NSLog(@"It obviously worked.1");
break;
case 2:
NSLog(@"It obviously worked.2");
break;
case 3:
NSLog(@"It obviously worked.3");
break;
case 4:
NSLog(@"It obviously worked.4");
break;
case 5:
NSLog(@"It obviously worked.5");
break;
case 6:
NSLog(@"It obviously worked.6");
break;
default:
NSLog(@"It did kindof work.NIL");
break;
}
}
有什么办法可以简化这个吗?只是这样做,
NSLog(@"It did work! %@", row);
为了记录,我试过了,并没有奏效。
哈,我是这样的noob .. 是否有格式说明符等地方的任何概述? 谢谢:) – Emil 2010-02-09 19:37:36
只需在C printf上进行搜索,它不会列出%@,但它包含了其他所有内容。 – 2010-02-09 19:52:46
@Emil:此链接包含Core Foundation支持的所有格式说明符:http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265。 – dreamlax 2010-02-09 23:49:18