以前选中cell时,常常判断选中的行数,但是当cell的顺序发生变化时,就要改动处理函数,特别是行数比较多的时候,很麻烦。
之后运用cell的title的内容判断,但是这种判断与现实的内容密切相关,如果改了title内容,也需要改动处理代码,也不正规。
最标准的方法是,声明一个枚举类型,enum,这样如果改动了cell的顺序,只需要改动enum的定义就可以。
代码如下:
typedef NS_ENUM(NSInteger, MMProgressHUDDemoFeatureType) { MMProgressHUDDemoTypeStylePlain = 0, MMProgressHUDDemoTypeStyleBordered, MMProgressHUDDemoTypeStaticImage, MMProgressHUDDemoTypeAnimatedImage, MMProgressHUDDemoTypeAutosizing, MMProgressHUDDemoTypeConfirmation, MMProgressHUDDemoTypeRadialProgress, MMProgressHUDDemoTypeLinearProgress, MMProgressHUDDemoTypeOverlayColor, MMProgressHUDDemoTypeImageRemove, }; switch (indexPath.section) { caseMMProgressHUDDemoSectionFeatures: switch (indexPath.row) { caseMMProgressHUDDemoTypeAnimatedImage: break; caseMMProgressHUDDemoTypeAutosizing: break; caseMMProgressHUDDemoTypeConfirmation: } break; }