我使用枚舉來填充UITableView。現在在運行時,在獲取服務器數據之後,我需要決定是否填充第一部分。所以,我需要刪除第一個枚舉(MyListSectionType1)條目以使其工作。在運行時定義枚舉以填充UITableView
typedef enum {
MyListSectionType1,
MyListSectionType2,
MyListSectionType3,
MyListSectionType4,
MyListSectionType5,
MyListSectionType6,
MyListSectionType7,
MyListSectionTypeMax,
} MyListSectionType;
我想用下面的代碼嘗試,但如何在運行時定義showShow是另一個問題。我試圖在我得到服務器數據的類中定義它,但這不起作用。任何線索?
typedef enum {
#ifdef showShow
MyListSectionType1,
#endif
MyListSectionType2,
MyListSectionType3,
MyListSectionType4,
MyListSectionType5,
MyListSectionType6,
MyListSectionType7,
MyListSectionTypeMax,
} MyListSectionType;
您不能在運行時更改'enum'。實際上,在運行時和'enum'不存在。它只是在編譯時轉換爲整數。你爲什麼不改變你的問題,因此它涵蓋了你正試圖解決的問題,而不是問一個可能的解決方案。 – rmaddy
因爲這是一個預處理器指令,所以無法使用#ifdef。在編譯時評估。 –