1

我最近发现它UIActionSheet实际上在它呈现之前缓存了它的可用委托选择器。

为什么不确定委托是否在确实需要知道时响应某个选择器?[delegate respondsToSelector:@selector()]执行起来真的很慢吗?我们应该在自己的代码中使用这种设计模式吗?任何想法,将不胜感激!

UIActionSheet.h 中的标志结构如下:

struct {
    unsigned int numberOfRows:7;
    unsigned int delegateAlertSheetButtonClicked:1;
    unsigned int delegateDidPresentAlertSheet:1;
    unsigned int delegateDidDismissAlertSheet:1;
    unsigned int hideButtonBar:1;
    unsigned int alertStyle:3;
    unsigned int dontDimBackground:1;
    unsigned int dismissSuspended:1;
    unsigned int dontBlockInteraction:1;
    unsigned int sheetWasPoppedUp:1;
    unsigned int sheetWasShown:1;
    unsigned int animating:1;
    unsigned int hideWhenDoneAnimating:1;
    unsigned int layoutWhenDoneAnimating:1;
    unsigned int titleMaxLineCount:2;
    unsigned int bodyTextMaxLineCount:3;
    unsigned int runsModal:1;
    unsigned int runningModal:1;
    unsigned int addedTextView:1;
    unsigned int addedTableShadows:1;
    unsigned int showOverSBAlerts:1;

    unsigned int showMinTableContent:1;
    unsigned int bodyTextTruncated:1;
    unsigned int orientation:3;
    unsigned int popupFromPoint:1;
    unsigned int inPopover:1;
    unsigned int delegateBodyTextAlignment:1;
    unsigned int delegateClickedButtonAtIndex:1;
    unsigned int delegateClickedButtonAtIndex2:1;
    unsigned int delegateCancel:1;
    unsigned int delegateCancel2:1;
    unsigned int delegateWillPresent:1;
    unsigned int delegateWillPresent2:1;
    unsigned int delegateDidPresent:1;
    unsigned int delegateDidPresent2:1;
    unsigned int delegateWillDismiss:1;
    unsigned int delegateWillDismiss2:1;
    unsigned int delegateDidDismiss:1;
    unsigned int delegateDidDismiss2:1;
    unsigned int dontCallDismissDelegate:1;
    unsigned int useAutomaticKB:1;
    unsigned int twoColumnsLayoutMode:7; // one column || even width (leaves empty space) || first button wider || last button wider
    unsigned int threeColumnsLayoutMode:7; // one column || even width (leaves empty space) || first button wider || last button wider
    unsigned int shouldHandleFirstKeyUpEvent:1; // when presenting with hardware KB we have to handle the first key up event we get so we don't end up repeating the last key
    unsigned int cancelWhenDoneAnimating:1;
    unsigned int useThreePartButtons:1; // phone numbers layout
    unsigned int useTwoPartButtons:1; // doc interaction layout
    unsigned int displaySelectedButtonGlyph:1;
    int indexOfSelectedButton:7; // default -1 (no checkmark) otherwise will display a checkbox (this for the airtunes action sheet)
    unsigned int useCustomSelectedButtonGlyph:1;
} _modalViewFlags;
4

0 回答 0