Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
I know method in Objective-C as defined as below:
Code:
- (void) classMethod: (int) first secondArgument:(int) second;
[B]-[/B]= Method type
[B](void)[/B]= return type
[B]classMethod[/B]= method name
[B](int)[/B]= first argument type
[B]first[/B]= first argument name
[B]secondArgument:[/B]= second argument label
[B](int)[/B]= second argument type
[B]second[/B]= second argument

But I am not sure what is the method name as below code, I thought method name should be numberOfRowsInSection and return type is (NSInteger), but I am in confuse about tableView:(UITableView *)tableView, what are they?
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of time zone names.
    return [timeZoneNames count];
}
 
Normally you wouldn't call it: it's a delegate method that will automatically be called by the UITableView. If you are struggling to understand this then I'm sorry but I don't have the time or energy to teach Objective-C basics. Apple have a very good document that covers the language.

To directly answer the question if we assume <i>instance</i> is an instance of the class implementing the method, <i>tableInstance</i> is the UITableView instance we are dealing with and <i>section</i> is the section we are interested in then the message syntax is:
Code:
NSInteger rowsInSection = [instance tableView:tableInstance numberOfRowsInSection:section];
 
Thanks for your answer.
I am reading that document what you suggested, but I couldn't find what I need so that I asked such simple question:(

This way can only be used for message syntax, is it right?

If use dot syntax, I think it should look like as below, do you think so?
Code:
- (NSInteger)numberOfRowsInSection:(UITableView *)tableView  sectionInTable:(NSInteger)section {
    // Return the number of time zone names.
    return [timeZoneNames count];
}
 
If use dot syntax, I think it should look like as below, do you think so?
Code:
- (NSInteger)numberOfRowsInSection:(UITableView *)tableView  sectionInTable:(NSInteger)section {
    // Return the number of time zone names.
    return [timeZoneNames count];
}

I don't see what this code has to do with dot syntax. Dot syntax is only used for properties.
 
Yeah, your are right, dot syntax is only for properties.

But I am still not sure about label of second argument, that doesn't explain the meaning of that argument...
numberOfRowsInSection:section
 
Yeah, your are right, dot syntax is only for properties.

But I am still not sure about label of second argument, that doesn't explain the meaning of that argument...
numberOfRowsInSection:section

The meaning of any argument is 100% down to the exact method being called. In this case it is the section that the table view wants to the number of rows in. The argument is simply section (a NSInteger). The numberOfRowsInSection is simply a name that is human readable to indicate to the caller what this argument is for (to prevent questions like this).
 
I don't see what this code has to do with dot syntax. Dot syntax is only used for properties.

You can use dot syntax for any getter method, it doesn't have to be a declared property. Whether you do or not is a matter of style but I tend to follow the rule of using dot syntax for queries but not commands. So I would use someArray.count but [someMutableArray removeAllObjects].
 
You can use dot syntax for any getter method, it doesn't have to be a declared property. Whether you do or not is a matter of style but I tend to follow the rule of using dot syntax for queries but not commands. So I would use someArray.count but [someMutableArray removeAllObjects].

Sure but I don't think you can use if for methods that take multiple arguments?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.