- 下面是幾種枚舉的列舉方式
- 定義整型值,但是不定義類(lèi)型
enum {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
- 定義適合特性參數(shù)的 UITableViewCellStyle 類(lèi)型。
typedef enum {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
} UITableViewCellStyle;
- 這種方法給出了 UITableViewCellStyle 確定的大小,但并沒(méi)有告訴編譯器這個(gè)類(lèi)型和之前的 enum 有什么關(guān)系
typedef enum {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
typedef NSInteger UITableViewCellStyle;
- NS_ENUM: NS_ENUM 的第一個(gè)參數(shù)是用于存儲(chǔ)的新類(lèi)型的類(lèi)型。在64位環(huán)境下,UITableViewCellStyle 和 NSInteger 一樣有8bytes長(zhǎng)。你要保證你給出的所有值能被該類(lèi)型容納,否則就會(huì)產(chǎn)生錯(cuò)誤。第二個(gè)參數(shù)是新類(lèi)型的名字。大括號(hào)里面和以前一樣,是你要定義的各種值。
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。