iOS中flags结构的目的是什么?

时间:2011-10-27 02:10:09

标签: c ios struct bitflags

struct
{
    unsigned resizesCellWidths:1;
    unsigned numColumns:6;
    unsigned separatorStyle:3;
    unsigned allowsSelection:1;
    unsigned backgroundViewExtendsUp:1;
    unsigned backgroundViewExtendsDown:1;
    unsigned usesPagedHorizontalScrolling:1;
    unsigned updating:1;
    unsigned ignoreTouchSelect:1;
    unsigned needsReload:1;
    unsigned allCellsNeedLayout:1;
    unsigned isRotating:1;
    unsigned clipsContentWidthToBounds:1;
    unsigned isAnimatingUpdates:1;
    unsigned requiresSelection:1;
    unsigned contentSizeFillsBounds:1;
    unsigned delegateWillDisplayCell:1;
    unsigned delegateWillSelectItem:1;
    unsigned delegateWillSelectItemMultiTouch:1;
    unsigned delegateWillDeselectItem:1;
    unsigned delegateDidSelectItem:1;
    unsigned delegateDidSelectItemMultiTouch:1;
    unsigned delegateDidDeselectItem:1;
    unsigned delegateGestureRecognizerActivated:1;
    unsigned delegateAdjustGridCellFrame:1;
    unsigned delegateDidEndUpdateAnimation:1;
    unsigned dataSourceGridCellSize:1;
    unsigned int isEditing:1;
    unsigned __RESERVED__:1;
} _flags;
  1. 这个结构的目的是什么?
  2. 每行末尾的:1符号表示什么?
  3. 当没有显式类型时,unsigned修饰符的含义是什么?
  4. 由于

1 个答案:

答案 0 :(得分:5)

那些是bitfields。由于大多数都是标志,因此它们只有2个可能的值,因此不需要为每个字段分配超过1位。 (在该结构中有几个例外)

unsigned可以单独作为一种类型。这只是一个unsigned int