style

 //普通
UITableViewStylePlain,
//分组
UITableViewStyleGrouped //表格视图
UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
//设置数据源
tableView.dataSource = self;
//设置代理
tableView.delegate = self;
//分区头的高度
tableView.sectionHeaderHeight = ;
//分区尾的高度
tableView.sectionFooterHeight = ; //行高,默认行高是44。
// tableView.rowHeight = 100;
// tableView.backgroundColor = [UIColor grayColor]; /* UITableViewCellSeparatorStyleNone 没有线
UITableViewCellSeparatorStyleSingleLine 单行线
UITableViewCellSeparatorStyleSingleLineEtched 被石化的单行线 //线的风格
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
// _tableView.separatorColor = [UIColor redColor];
//线的内边距
_tableView.separatorInset = UIEdgeInsetsMake(, , , ); //行高固定时使用
_tableView.rowHeight = ; //设置背景View
// UIImageView * imageView = [[UIImageView alloc] initWithFrame:tableView.bounds];
// imageView.image = [UIImage imageNamed:@"baby.jpg"];
// tableView.backgroundView = imageView; //索引区域的背景
_tableView.sectionIndexBackgroundColor = [UIColor whiteColor];
//设置索引文字的颜色
_tableView.sectionIndexColor = [UIColor blueColor];
//cell行数小于多少是展示索引
_tableView.sectionIndexMinimumDisplayRowCount = ;
//选择索引时的背景颜色
_tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor]; //设置编辑模式
[self.tableView setEditing:YES animated:YES]; //得到所有选中的行数
NSArray * deleteList = [self.tableView indexPathsForSelectedRows]; 代理 UITableViewDataSource,UITableViewDelegate
//几个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.peopleList.count;
} //Section是分组,Rows多少行,默认情况下只有一个Section.分组的index为0 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray * p = self.peopleList[section]; return p.count;
} //cell单元格,IndexPath索引 //UITableViewCell是组成UITableView的单元格 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [[UITableViewCell alloc] init]; cell.textLabel.text = self.peopleList[indexPath.section][indexPath.row]; //clearColor是透明颜色
cell.backgroundColor = [UIColor clearColor]; return cell;
} //返回分区顶部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return self.headList[section];
} //返回分区尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { return self.footList[section];
} //选中某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //取消选中某一行
[tableView deselectRowAtIndexPath:indexPath animated:YES]; //转到下一页
NSString * vcName = self.viewControllers[indexPath.section][indexPath.row]; UIViewController * vc = [[NSClassFromString(vcName) alloc] init];
[self.navigationController pushViewController:vc animated:YES]; } //section空隙之间的颜色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView * v = [[UIView alloc] init];
v.backgroundColor = [UIColor greenColor];
return v;
} //当滚动表格时,这个代理方法,一直调用
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //UITableViewCell的复用机制 static NSString * identifier = @"cellID"; //从复用池里找对应的cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { /* UITableViewCellStyleDefault 显示图片,显示辅助图片,显示一行文字
UITableViewCellStyleValue1 显示图片,显示辅助图片,普通文字,描述文字,共占一排
UITableViewCellStyleValue2 不显示图片,显示辅助图片,普通文字,描述文字,共占一排
UITableViewCellStyleSubtitle 显示图片,显示辅助图片,普通文字,描述文字,共占两排 */ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellID"];
} Industry * industry = self.dataList[indexPath.row]; cell.textLabel.text = industry.name; cell.detailTextLabel.text = industry.state; cell.imageView.image = [UIImage imageNamed:industry.icon]; cell.accessoryType = UITableViewCellAccessoryDetailButton; return cell;
} //设置行高方法,如果实现这个代理方法,rowHeight无效,这个主要用于设置可变cell高度
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//
// return 100;
//} //显示索引的题目 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [self.dataList valueForKey:@"title"];
} //返回表格视图是否可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES;
} //返回表格视图是否可以滚动 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES;
} //确定编辑的选项
/*
UITableViewCellEditingStyle UITableViewCellEditingStyleNone 不编辑
UITableViewCellEditingStyleDelete 删除
UITableViewCellEditingStyleInsert 插入
*/ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { //如果是删除操作
if (editingStyle == UITableViewCellEditingStyleDelete) { //从数据源删除数据
[self.dataList removeObjectAtIndex:indexPath.row]; //根据indexPath数组删除元素 NSArray * deleteIndexs = @[indexPath]; //UITableViewRowAnimation 操作动画
[tableView deleteRowsAtIndexPaths:deleteIndexs withRowAnimation:UITableViewRowAnimationFade]; }
} -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.dataList removeObjectAtIndex:indexPath.row]; //刷新表格
// [tableView reloadData]; //刷新删除操作
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { //插入操作
[self.dataList insertObject:@"baby" atIndex:indexPath.row]; [tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
} //移动必须实现的方法
//sourceIndexPath 起始位置
//destinationIndexPath 目标位置 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NSString * name = self.dataList[sourceIndexPath.row]; [self.dataList removeObjectAtIndex:sourceIndexPath.row]; [self.dataList insertObject:name atIndex:destinationIndexPath.row]; } //修改删除按钮 - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"真的要删除吗";
} //默认返回UITableViewCellEditingStyleDelete - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { // return UITableViewCellEditingStyleInsert;
return UITableViewCellEditingStyleDelete;
} - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { //多选
return UITableViewCellEditingStyleInsert|UITableViewCellEditingStyleDelete;
}

最新文章

  1. java 用插入排序思想,对不规则数组排序。
  2. NYOJ题目10505C?5S?
  3. Jquery学习—jquery的事件
  4. 向MyEclipse添加Oracle数据库
  5. Nginx(一)初始环境的安装(php5.3+mysql5.1+fastcgi…)
  6. 李洪强iOS开发Swift篇—10_方法
  7. javascript-几个基础的排序算法
  8. Xshell中文乱码
  9. poj2405---体积几何
  10. Spring详解(五)------AspectJ 实现AOP
  11. Python 中的 if __name__ == '__main__' 该如何理解
  12. 深入Vue2.x的虚拟DOM diff原理
  13. 使用Visual Studio Team Services敏捷规划和项目组合管理(二)——VSTS中的工作项
  14. 网络编程 -- RPC实现原理 -- NIO多线程 -- 迭代版本V1
  15. LeetCode Merge k Sorted Lists (链表)
  16. 精通Docker的50个必备教程、工具、资源
  17. JavaScript的数据类型和运算符总结
  18. mysql和SQLAlchemy
  19. Android 画闹钟
  20. webstorm设置修改文件后自动编译并刷新浏览器页面

热门文章

  1. 博客已经迁移至http://www.xuechenlei.com
  2. Python科学计算包模块的安装(ubuntu)
  3. 一个不错的php验证码的类
  4. ASP.NET MVC 网站开发总结(五)——Ajax异步提交表单之检查验证码
  5. RSA加密解密(python版)
  6. 理解Ruby中的作用域
  7. log4j在javaWeb项目中的使用
  8. Java Collection或Map的同步
  9. HTML学习总结
  10. jQuery演示10种不同的切换图片列表动画效果