UIActionSheet addButtonWithTitle: doesn't add buttons in the right order

前端 未结 3 875
后悔当初
后悔当初 2021-01-04 21:27

I\'ve subclassed UIActionSheet, and in the -init method, I have to add the buttons individually after calling the super init (can\'t p

3条回答
  •  日久生厌
    2021-01-04 22:04

    You can just add them in your correct order, and then set the cancelButtonIndex and destructiveButtonIndex manually.

    For your code example:

    if (self = [super initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTile:nil otherButtonTitles:nil]) {
      if (firstButton) {
        id buttonTitle;
        int idx = 0;
        va_list argList;
        va_start(argList, firstButtton);
        while (buttonTitle = va_arg(argList, id)) {
          [self addButtonWithTitle:buttonTitle]
          idx++;
        }
        va_end(argList);
        [self addButtonWithTitle:cancel];
        [self addButtonWithTitle:destroy];
        self.cancelButtonIndex = idx++;
        self.destructiveButtonIndex = idx++;
      }
    }
    return self;
    

提交回复
热议问题