【发布时间】:2013-11-04 20:54:04
【问题描述】:
我正在使用枚举填充 UITableView。现在在运行时,在获得服务器数据后,我需要决定是否填充第一部分。因此,我需要删除第一个枚举 (MyListSectionType1) 条目以使其正常工作。
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并不存在。这一切都只是在编译时转换为整数。你为什么不改变你的问题,让它涵盖你试图解决的问题,而不是询问一种可能的解决方案。 -
无论如何你都不能用#ifdef 来做,因为这是一个预处理器指令。在编译时评估。
标签: ios objective-c cocoa-touch uitableview enums