您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页UITableView的简单使用

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;

}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务