Naming guidelines for the selector methods of gesture recognizers?
I started off naming my selector methods generically based on a description of the gesture itself but with the word "handle" in front. For example:
UITapGestureRecognizer *aRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleOneFingerSingleTap:)];
But then I wanted different be开发者_如何学JAVAhavior (and different selector methods) for the same gesture in different views. Then I started naming my selector methods based on what I wanted to happen. For example:
UITapGestureRecognizer *aRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleShowMyPopover:)];
However, I'm not sure that is going to make sense in the long run either. For one thing, the method name alone does not obviously indicate that it is a gesture recognizer selector. Or maybe the word "handle" indicates it is a selector method? Do I even need to worry about that?
So that is why I'm asking: to see if anyone has preferences (based on experience) for how they name their gesture recognizer selectors.
I searched the Coding Guidelines for Cocoa Naming Methods page but found nothing obvious.
Just in case it matters for this discussion, I create and assign gesture recognizers to views in the view controller, and the selector methods live in the view controller also.
I also went through an exploratory process and settled on (just one man's opinion):
- Use a descriptor of what the gesture accomplishes as the verb. This lets you distinguish between multiple handlers for the same gesture type being used for different (semantic) actions.
- Suffix the method name with "Gesture"
- Always use the selector form that takes the recognizer parameter, and use the specific subclass type in the signature.
Format:
- (void)thingItAccomplishesGesture:(UISpecificGestureRecognizer *)recognizer;
Example: a tap gesture recognizer that opens a document, I'd call it:
- (void)openDocumentGesture:(UITapGestureRecognizer *)recognizer;
精彩评论