TableView基础篇
来源:互联网 发布:火蓝刀锋知乎 编辑:程序博客网 时间:2024/06/15 08:00
第一,初始化
可以使用懒加载进行初始化;(懒加载就是利用get方法进行初始化)
//界面布局
UITableView *tableView_list = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, XSCREENWIDTH, XSCREENHEIGHT)];
tableView_list.backgroundColor = [UIColor clearColor];
tableView_list.dataSource = self;
tableView_list.delegate = self;
tableView_list.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableView_list];
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identify = @"Identify";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
//列表头部
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView_list.width, 30)];
backView.backgroundColor = ColorForViewBg;
return backView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
第二,tableView索引的设置
索引显示设置
tableView_list.sectionIndexColor = [UIColor blueColor]; //字体颜色
tableView_list.sectionIndexBackgroundColor = [UIColor clearColor];//索引背景颜色
以下两句是索引的关键
//返回索引栏数据
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return array_section;
}
//建立索引栏和section的关联
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return [array_section indexOfObject:title];
}
第三,滑动删除
首先要设置cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
显示的字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"删除";
}
删除对应的操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//[self deleteAction_myCar:indexPath.row];
}
}
0 0
- TableView基础篇
- UI基础 tableView
- TableView基础(view上添加tableView)
- [IOS]关于设计TableView和TableViewCell之基础篇
- IOS 学习笔记(9)tableView基础
- IOS开发-TableView表视图基础
- IOS 学习笔记(9)tableView基础
- ios之基础tableview的问题总结
- 一些tableView的基础Knowledge(2015414)
- IOS学习之——TableView基础
- TableView
- TableView
- tableview
- tableview
- tableview
- TableView
- TABLEVIEW
- tableView
- 规则引擎简介
- 常用正则表达式
- 轻松搞定二叉树中的面试题
- android 简单联网判断
- Docker安装
- TableView基础篇
- Python编程技巧(一)
- Hibernate单表操作
- 基于归并排序的实现与应用
- 知道这20个正则表达式,能让你少写1,000行代码
- 【UNET自学日志】Part10 摧毁玩家
- Eclipse IDE for C/C++ 配置
- 8(进程控制)
- 自定义初学5——自定义View显示图片