开发者

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):

  1. 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.
  2. Suffix the method name with "Gesture"
  3. 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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜