0

Possible Duplicate:
Method Syntax in Objective C

I'm quite new to iPhone development and I'm confused about the method declaration iPhone development using X-code

Please help me identify what is the name of the method here.

tableView or willSelectRowAtIndexPath

Please explain how did you recognize it. Thanks in advance.

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSUInteger row = [indexPath row];
    if (row == 0) return nil;
    return indexPath;
}
Community
  • 1
  • 1
Pawan Sharma
  • 3,199
  • 1
  • 25
  • 32

3 Answers3

1

The method signature is tableView:willSelectRowAtIndexPath:. Here you can read about method names in Objective C - http://cocoawithlove.com/2009/06/method-names-in-objective-c.html Ask more if you're unsure why and what's going on here.

zrzka
  • 20,249
  • 5
  • 47
  • 73
  • (+1), but... You could argue that, given the context of UIKit, a more specific method name is `-[UITableViewDelegate tableView:willSelectRowAtIndexPath:]`. I know this is nit-picking but it is often useful to know which class a method belongs to. Of course, the counter argument is that, we do not know if this is the UIKit method I am referring to or something of the OP's own design. – idz Aug 16 '12 at 08:33
  • Yeah, you're right, but if we look at method name from the selector point of view, it's correct. It's more complicated than this, but ... :) – zrzka Aug 16 '12 at 08:40
1

method name is – tableView:willSelectRowAtIndexPath: you can easily know it on Xcode by holding alt/option key and click on the method you want to get information.

EDIT:

– tableView:willSelectRowAtIndexPath: is a method "signature/name" it is declared in code as

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableView : type is UITableView

A table-view object informing the delegate about the impending selection.

indexPath : type is NSIndexPath

An index path locating the row in tableView.

Return Value () type is NSIndexPath

An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don't want the row selected.

-- as seen here

janusfidel
  • 8,036
  • 4
  • 30
  • 53
  • Thank for your answer but I'm still confused that a method name like "tableView:willSelectRowAtIndexPath" is a valid name in objective-c, because many languages like java, C, C++ don't allow any special character like : in method signature declaration. – Pawan Sharma Aug 16 '12 at 08:48
  • Objective C message sending do not use the syntax and rules of java/C/C++ etc. It is similar to Smalltalk messages. Those names are made of multiple parts and the arguments are not specified in parenthesis after the name as in C++ but interleaved with the name instead. Note that it's even slightly imprecise to consider them method names. Technically methods do not have names, they are nameless code that is executed in response to a message. Those names are the names of the message. But it's in practice very common to consider them method names. – Analog File Aug 16 '12 at 19:55
-1

The method name is -tableView: willSelectRowAtIndexPath:

The words after ':' before 'space' are parameters

words within the ()are parameter type

PS:of course the first () is return type

Jimmy
  • 1,094
  • 10
  • 22