iOS UITableView
来源:互联网 发布:红警模型淘宝 编辑:程序博客网 时间:2024/05/20 05:29
UITableView 是 iOS 中用得相当多的一个控件。
两个协议:UITableViewDataSource, UITableViewDelegate.
每个分区称为一个 section, 每一行称为一个 row, 编号都是从 0 开始。
方法:
- 设置多少区:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- 设置多少行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- 设置表的内容:
// 常用如下设置:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // 配置内容 return cell;}
- 设置区头:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- 设置区头的高度:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- 表的点击事件:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- 设置 Cell 的高度:
// 动态的设置每个cell的高度,适用于不等高的cell.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
注意:如果是等高的 cell, 可以设置 tableView.rowHeight 属性,是每行等高;若不设置,默认 cell 的高度 44.
- 设置内容缩进(暂未用到,待验证):
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;
- 数组中返回右边的索引显示的内容(暂未用到,待验证):
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
- 滑动选择的行后删除(暂未用到,待验证):
// 提交编辑。只要实现了这个方法,就可以实现左滑出现按钮。- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
- 提交编辑出现的按钮(暂未用到,待验证):
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath; //数组中装的是UITableViewRowAction对象
参考:
1. IOS控件UITableView详解
2. UI第九天:UITableView简单介绍
3. UITableView
0 0
- IOS UITableview
- ios UITableView
- iOS- UITableView
- ios UITableView
- IOS UITableView
- IOS UITableView
- Ios-UITableView
- iOS UITableView
- iOS UITableView
- IOS-UITableView
- IOS UITableView
- iOS-------UITableView
- iOS UITableView
- iOS UITableView
- ios UITableView分页加载
- IOS UITableView下拉刷新
- IOS控件UITableView详解
- ios UITableView分页加载
- C++:标准库类型(string、vector、list、bitset)
- 挖掘频繁项集之FP-Growth算法
- UVA_1592: Database
- Android Notivation的使用
- Android 获取服务器数据解析Text数据,存在htmel标签的处理办法
- iOS UITableView
- Objective-C NSFileManager 管理文件和目录
- C程序中丢弃输入行无用的代码
- iOS软件开发 Core Data的使用
- 我的SBJson来生成和解析JSON串的代码
- Gym 100685G Gadget Hackwrench (LCA)
- hdu5497 Inversion
- 求解集合A与B的差集
- Merge Two Sorted Lists and Merge k Sorted Lists