UI基础--UITableView,UITableViewDataSource,UITableViewDelegate的一些属性和方法

UITableView(继承自UIScrollView)的常用属性

1、可以用连线的方式设置数据源和代理

1 self.tableView.dataSource = self;
2 self.tableView.delegate = self;

2、设置高度

1 @property (nonatomic)   CGFloat rowHeight;//行高
2 @property (nonatomic)   CGFloat sectionHeaderHeight; //组头的高度
3 @property (nonatomic) CGFloat sectionFooterHeight; //组尾的高度

3、设置分割线

1 @property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;//分割线样式
2 @property(nonatomic,retain) UIColor;//分割线的颜色

4、设置tableView是否分组(默认在storyboard中已经设置)

1 @property (nonatomic, readonly) UITableViewStyle;//UITableViewStylePlain,    不分组;UITableViewStyleGrouped   分组

5、自定义头和尾部

1 @property(nonatomic,retain) UIView *tableHeaderView;//头部
2 @property(nonatomic,retain) UIView *tableFooterView;//尾部

UITableViewDataSource的常用方法:

1 @required
2 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;// 每一组有多少行数据
3 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;// 每一个cell都包含什么内容(image、textLabel、detailTextLabel,还有一个就是附属物)
4 @optional
5 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // 一个tableView有多少组的数据 ,默认是1
6 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; - (NSString *)tableView:(UITableView *)tableView //每一组的头标题
7 //titleForFooterInSection:(NSInteger)section;//每一组的尾标题
8 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; // 返回右侧导航标题(包含的是每组头标题的数组)

UITableViewDelegate的常用方法:

1 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;//每组数据中的行高
2  - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;//每组数据的组头的高度
3 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;//每组数据的组尾的高度
4 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; //每行被选中时的操作

UITableViewCell的重用:

cell的性能优化:当cell滑出屏幕(不用之后),把cell对象存储在特定标示的缓存池,当tableView加载下一个数据的时候,从缓存池中取出空闲的cell:

1 static NSString *reuseIdentifier = @"cell";//设置缓冲池标识
2 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
3 if (!cell) {
4 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];//当缓存池里暂时没有空闲的cell时,初始化一个cell
5 }
时间: 2024-08-26 15:32:27

UI基础--UITableView,UITableViewDataSource,UITableViewDelegate的一些属性和方法的相关文章

IOS开发UI基础UITableView的属性

UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped <UITableViewDataSource,UITableViewDelegate>里的方法: tableView处理步骤 #pragma mark 1.有多少组- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView #pragma mark 2.第section组

UI基础--UITableView实现仿QQ聊天页面

需求:类似于QQ聊天页面的展示,内容包括有头像.时间.聊天内容.相同时间发生的内容,只显示第一条内容的时间,并且点击输入框时,可以滚动到最后一条内容信息.具体效果图: 实例的文件结构: 实现的具体步骤: 1.布局界面,主要包括一个UIImageView.3个UIButton.1个UITextField: 2.自定义数据模型类,并测试数据是否能正常加载: 3.自定义cell,由于每行数据的高度都是不规则的,所以考虑先自定义好frame再来写自定义cell.属性包括frame模型以及生成可重用cel

JavaScript基础对象创建模式之私有属性和方法(024)

JavaScript没有特殊的语法来表示对象的私有属性和方法,默认的情况下,所有的属性和方法都是公有的.如下面用字面声明的对象: var myobj = { myprop: 1, getProp: function () { return this.myprop; } }; console.log(myobj.myprop); // `myprop` is publicly accessible console.log(myobj.getProp()); // getProp() is publ

UITableView / UITableViewDataSource / UITableViewDelegate

一张图解释TableView各属性 0 UITableView Initializing a UITableView Object 初始化: - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style Configuring a Table View 配置: 1. style /** TableView样式,默认Plain */ @property(nonatomic, readonly) UITableVi

UI基础--UITableView实现仿微博页面

需求:类似于微博内容页面的展示,内容包括有头像.呢称.会员标志.微博内容.微博图片(可有可没有).具体效果图: 实例的文件结构: 实现的具体步骤: 1.自定义数据模型类,并测试数据是否能正常加载: 2.设置storyBoard,把UIViewController改为UITableViewController,,并更改controller文件为继承自UITableViewController的自定义文件,设置关联; 3.自定义cell,由于每行数据的高度都是不规则的,所以考虑先自定义好frame再

UI基础:UITableView的编辑和移动

相对UITableViiew进行编辑,必须设置代理UITableViewDataSource和UITableViewDelegate.因为需要它们为UITableViiew实现几个必须的方法. UITableView的编辑和移动都遵循四步操作: 1.让tableView处于可编辑状态(UIViewController中的方法) 2.设置哪些行可以编辑(UITableViewDataSource中的方法) 3.设置编辑的样式(UITableViewDelegate中的方法) 4.提交编辑(a.修改

UI基础--UITableView实现仿QQ好友列表页面

需求:类似于QQ好友列表页面的显示,有好友分组,有好友数量,在线人数,vip会员.展开分组时显示分组好友,合并分组时不显示:具体效果图如下: 分析: 1.展开分组时显示分组好友,该功能可以使用显示UITableViewCell的数据即可: 2.分组头可以考虑使用一个headerView来实现: 示例文件结构: 具体实现步骤: 1.自定义数据模型类,由于plist文件中包含了2个字典,所以需要写2个数据模型: 2.自定义cell,属性包括数据模型以及生成可重用cell的方法,由于系统自带的子控件即

IOS UI学习 UITableView ----- UITableViewDataSource

UITableView派生自UIScrollView UITableView结构如下: 背景是滚动视图,每个横向的表格称为cell ( UITableViewCell ) 每一个 cell 既可以存储数据,也可以接受选中的事件, 我们选中某个cell时,可以下拉列表,可以推出新的页面 在编辑模式选中多个cell,可以批量删除等. 成员变量 1 { 2 UITableView * _tableV; 3 NSMutableArray * _dataArr; 4 UISearchController

UI基础之UITableView的基本使用

UITableView控件 1,基本使用(required) UITableView有两种样式:grouped/plain 组/单行 UITableView需要?一个数据源(dataSource)来显示数据UITableView会向数据源查询一共有多少行数据以及每?行显示什么数据等 没有设置数据源的UITableView只是个空壳 凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的数据源 展示数据的过程: (1)调用数据源的下面?法得知?一共有多少