UITableView的简单使用

一 简单介绍

1. tableView.dataSource = self  设置代理

2.   必须实现三个方法

tableView中 有多少组

numberOfSectionsInTableView:

每一组有多少行

numberOfRowsInSection:

每一行要显示的内容

cellForRowAtIndexPath:

3.  tableView的样式    plain   group     组头和组尾 有悬浮效果

4.  组头和组尾

titleForHeaderInSection:

titleForFooterInSection:

5.隐藏 状态栏   prefersStatusBarHidden

6._tableView.rowHeight = 100

代理方法, 可以为每个cell 设置不同的行高

heightForRowAtIndexPath:


二 代码示例

- (void)viewDidLoad {

[superviewDidLoad];

//设置控制器成为tableView的数据源代理

_tableView.dataSource=self;

}

/**

每一个tableView有多少组

如果不实现,默认就会返回1

*/

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {

return1;

}

/**

要显示100行的数据

section :组

*/

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

return100;

}

/**

每一行上要显示的内容

UITableViewCell: cell,就是每一个格子

indexPath :包括了,行和组-->可以唯一确定一行

*/

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

UITableViewCell*cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:nil];

//设置label的文本

cell.textLabel.text=@"hello cell";

returncell;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容