开发者

Where does this method's arguments get passed from?

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;

@end

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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜