UITableView 如何展示数据

 

如果想要在UITableView中添加数据,需要一个数据源(dateSource)来显示数据

 

1.首先添加数据源

@interface PPViewController () <UITableViewDataSource>

2.遵守协议,实现数据源

#pragma mark - 数据源

//一共有多少组数据

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

//每一组中添加多少行数据

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

//每一行数据显示的内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//创建cell
  UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]

}

3.返回数据

self.TableView.dataSource = self;

4.UITableView还提供了两种头尾

//显示头部标题

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

//显示尾部标题

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

 

2014-06-18 

posted on 2014-06-18 21:54  peng~zZ  阅读(654)  评论(0)    收藏  举报

导航