Take the 2-minute tour ×

Simple question: where do the tableView and section arguments get passed from? The actual code in the method return [self.listData count]; doesn't even mention them.

Here's my interface code:

@interface Simple_TableViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource>
NSArray *listData;

@property (nonatomic, retain) NSArray *listData;


And this is all the implementation code:

#import "Simple_TableViewController.h"

@implementation Simple_TableViewController
@synthesize listData;

- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", 
                  @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", 
                  @"Dorin", @"Nori", @"Ori", @"Balin", @"Dwalin", @"Fili", @"Kili",
                  @"Oin", @"Gloin", @"Bifur", @"Bofur", @"Bombur", nil];
self.listData = array;
[array release];
[super viewDidLoad];

- (void)viewDidUnload {
self.listData = nil;

- (void)dealloc {
[listData release];
[super dealloc];

#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section {
    return [self.listData count];

I just want to know how does the method (NSInteger)tableView: (UITableView *)numberOfRowsInSection: receive those arguments? Of course this happens everywhere; I just want to understand it.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

The Simple_TableViewController class is likely meant to manage a single table with a single section. Given that, the tableView and section parameters aren't important because they can only be one thing: a pointer to the table and 0, respectively.

share|improve this answer
This is true, but does that mean all arguments in all methods aren't required? Or do they have defaults? Also, I know that method is triggered through the delegate, but how do I know which event does the triggering? –  Trevor McKendrick Mar 23 '11 at 5:47
The table data source has to implement certain methods with specific interfaces. -tableView:numberOfRowsInSection: is a good example -- the data source doesn't get to rewrite the method name to eliminate unneeded parameters -- if it did, how would UITableView know what method to call? So, in this case, the table is giving its data source more information than it needs to answer the question "How many rows are there?" The method isn't obligated to use all its parameters. –  Caleb Mar 23 '11 at 6:21
add comment

Your view controller class is adding support for these callback methods through UITableViewDelegate and UITableViewDataSource. You are adding this support in your .h file through <UITableViewDelegate, UITableViewDataSource>. These classes are built in to the Cocoa Touch framework and you are just using them. When the table is (re)loaded, this callback methods are called if you have defined them (some are required, others are optional).

share|improve this answer
add comment

Your Answer


