爲什麼不這項工作:爲什麼我不能在switch語句中使用NSInteger?
NSInteger sectionLocation = 0;
NSInteger sectionTitles = 1;
NSInteger sectionNotifications = 2;
switch (section) {
case sectionLocation:
//
break;
case sectionTitles:
//
break;
case sectionNotifications:
//
break;
default:
//
}
我得到這個編譯錯誤:
error: case label does not reduce to an integer constant
是沒可能使用NSInteger的是這樣的?如果是這樣,是否有另一種方法在switch語句中使用變量作爲例子? sectionLocation
等有可變值。
因此,我將不得不訴諸的if-else-if-else語句來着?這有沒有解決辦法? – Rits 2011-01-08 19:14:00