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;
}

UITableView详细注释的更多相关文章

  1. Qt5_简易画板_详细注释

    代码下载链接:  http://pan.baidu.com/s/1hsc41Ek 密码: 5hdg 显示效果如下: 代码附有详细注释(代码如下) /*** * 先新建QMainWindow, 项目名称 ...

  2. 51nod 1126 求递推序列的第N项 思路:递推模拟,求循环节。详细注释

    题目: 看起来比较难,范围10^9 O(n)都过不了,但是仅仅是看起来.(虽然我WA了7次 TLE了3次,被自己蠢哭) 我们观察到 0 <= f[i] <= 6 就简单了,就像小学初中学的 ...

  3. 一套强大的vim配置文件+详细注释

    phpchina折腾王独家配置,灰常牛叉的一套vim配置,另附有详细注释,自己折腾vim的时候可以参照其中的大部分设置进行一些个性化定制."是否兼容VI,compatible为兼容,noco ...

  4. MFC的PNG贴图按钮类(详细注释)

    MFC的PNG贴图按钮类(详细注释) (转载请注明出处) 作者:梦镜谷雨 萌新第二次写帖子,请多多包涵.末尾附上相应代码(PS公司繁体系统所以部分注释繁体请别介意). 因自带控件不美观,于是网上参考学 ...

  5. dedecms首页入口的详细注释

    今天闲来无事,就拿来dede首页的文件给大家详细解释一遍,以便于新手学习,注释过程非常非常非常的详细,里面解释到dede表前缀#@__代替的原理.解释到dede很多自定义函数的具体位置和具体作用等等疑 ...

  6. 详细注释!二维码条码扫描源码,使用Zxing core2.3

    from:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=325529&page=1 现如今很多项目中都会应用到条码扫描解 ...

  7. 紫书 例题8-17 UVa 1609 (构造法)(详细注释)

    这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上 ...

  8. Umi + Dva的数据传递学习Demo(代码有详细注释)

    刚学习时写了篇笔记,以免自己忘记,用了一段时间后,觉得不如做个demo,代码写上注释,方便也在学习umi-dva的同学们理解更好,更容易上手. 这可能是网上注释最多,看了最易理解的学习小指南吧,哈哈. ...

  9. Light OJ - 1026 - Critical Links(图论-Tarjan算法求无向图的桥数) - 带详细注释

     原题链接   无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 也可以先用Tajan()进行dfs算出所有点 的low和dfn值,并记录dfs过程中每个 点的父节点:然后再把所有点遍历一遍 ...

随机推荐

  1. linux中不小心将rpm命令卸载了,怎么恢复?

    今天在搭建mysql的集群服务时,安装mysql集群服务前,先卸载原来mysql的软件包,不小心将rpm的命令也给卸载掉了,这下惨了,什么也做不了了.在google了翻了好多个页面,甚至官网也看了,没 ...

  2. MySQL5.7(5.6)GTID环境下恢复从库思(qi)路(yin)方(ji)法(qiao)

      要讨论如何恢复从库,我们得先来了解如下一些概念: GTID_EXECUTED:它是一组包含已经记录在二进制日志文件中的事务集合 GTID_PURGED:它是一组包含已经从二进制日志删除掉的事务集合 ...

  3. AMD64和i386的区别

    下载Debian系统时,出现两个选项:ADM64和i386,那么这两者的区别是什么? i386=Intel 80386.其实i386通常被用来作为对Intel(英特尔)32位微处理器的统称. AMD6 ...

  4. 二维码详解(QR Code)

    作者:王子旭链接:https://zhuanlan.zhihu.com/p/21463650来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 2016.7.5 更新:长文 ...

  5. [小工具]CSS内嵌样式自动提取器

    逐行分析,将内联样式提取出来,并自动编号代替的一个小工具软件 注:style=""(此处必须是标准的双引号!) http://files.cnblogs.com/quejuwen/ ...

  6. QTableWidget的美化

      FriendTable->setFrameShape(QFrame::NoFrame);  //设置边框 FriendTable->setHorizontalHeaderLabels( ...

  7. 对于一些Http远程连接Api安全的看法;

    文章来源于 :http://lesg.cn/?p=122 我的个人博客站点 对于一些Http远程连接Api安全的看法: 当不同系统需要互相通信的时候:如果无法用webservice等方式链接的时候另一 ...

  8. Delphi Berlin 10.1 for 小米平板2 (Win 10) 电子罗盘测试

    Windows 10 下没有 Sensor.HeadingXSensor.HeadingYSensor.HeadingZ 需改用 Sensor.CompMagHeading

  9. (学习笔记)PHP的输出echo和print

    echo 和 print 之间的差异: echo - 能够输出一个以上的字符串 print - 只能输出一个字符串,并始终返回 1 echo语句 echo 或 echo()均可. 输出换行 echo ...

  10. EffectiveJava——请不要在代码中使用原生态类型

    先看一个栗子,看看能不能找出来里面的错误: /** * 请不要在新代码中使用原生态类型 * @author weishiyao * */ public class Test { public stat ...