UITableView DataSource

UITableView需要一个数据源(datasource)来显示数据

@protocol

UITableViewDataSource

一个tableView的数据源,必须要实现的方法

@required

//返回每一个分组里有多少个cell(每一个分组有多少行)

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

//indexPath对应某一组,某一行 ,返回当前行,当前列对应的cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

一个tableView的数据源,可选实现的方法

@optional

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              //这个方法如果没有被实现,那么section默认为1,即一共1组

//设置每一个分组的Header 和Footer

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

 

 tips:当然别忘记在.m文件中,声明这个协议。@interface<UITableViewDataSource>

posted @ 2014-05-27 16:04  Shdow_Walker  阅读(227)  评论(0编辑  收藏  举报