6.14.1 UITableViewDataSource协议方法初始化数据
     //设置组与组之间的间距
    self.tableView.sectionHeaderHeight=5;//footer
   

//将类与代理类建立关联,用代码或者利用连线的方式来实现

self.tableView.dataSource = self;

 
//设置tableView分组

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

 //设置tableview每一组Section的行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

 //设置cell属性和样式
- (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//添加右侧索引文字

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{

return [self.carsGroups valueForKeyPath:@"title"];

}
/tableView进入编辑状态后,每行cell编辑按钮的样式设置

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath

{

if (indexPath.row == 0) { // 第一行是插入样式

return UITableViewCellEditingStyleInsert;

}else{

return UITableViewCellEditingStyleDelete;

}

}
//重写该方法,可实现cell滑动删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  //先删除数据模型中的数据
   [self.contacts removeObjectAtIndex:indexPath.row];
  //再局部刷新tableVewl中的cell信息
   [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
1.1.1 }UITableViewDetegate协议方法监听操作
//tableview选中监听方法实现
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:

(NSIndexPath *)indexPath{}
//tableview逐行设置cell行高监听方法实现
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:
6.14.2 TableView常用属性

//设置滚动区域的偏移

self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
//设置行高

self.tableView.rowHeight = 60;

//设置分割线

self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

//设置分割线颜色

self.tableView.separatorColor = [UIColor brownColor];

//cell不允许选中

self.tableView.allowsSelection = NO;

//设置分组行高

self.tableView.sectionHeaderHeight = 50;

//进入编辑状态

self.tableView.editing = YES;

 
/设置头部和尾部的view,同一个view来设置头部和尾部时,默认只能显示头部的

UISwitch *swithBth = [[UISwitch alloc] init];

UISwitch *swithBth1 = [[UISwitch alloc] init];

self.tableView.tableHeaderView = swithBth;

self.tableView.tableFooterView = swithBth1;

 TableView方法
1. 刷新

全部或者局部reload,都是触发tableView:cellForRowAtIndexPath:方法,创建或重用cell,局部刷新cell时还可实现动画效果。而cell.textLabel.text是直接赋值,只是更新了页面上的label属性,不触发任何事件。

reload方法执行后会清空缓存池。
2. 滚动到指定位置
 方法一:滚动到指定的单元格

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

 //方法二:可滚动到tableView底部,scrollToRowAtIndexPath只能滚动到最后一个cell,

​​如果tableview包含tableFooterView则需要自己定位

[UIView animateWithDuration:0.5 animations:^{

CGFloat height = self.tableView.contentSize.height - self.tableView.frame.size.height;

[self.tableView setContentOffset:CGPointMake(0, height)];

}];

CeLL重用

Cell常用属性

/*设置backgroundView和selectedBackgroundView的背景颜色时不要直接设置cell.backgroundView.backgroundColor和cell.selectedBackgroundView.backgroundColor

应该创建ImageView后设置其backgroundColor再赋值*/

UIImageView *view = [[UIImageView alloc] init];

view.backgroundColor = [UIColor greenColor];

cell.backgroundView = view;

 UIImageView *view1 = [[UIImageView alloc] init];

view1.backgroundColor = [UIColor blueColor];

cell.selectedBackgroundView = view1;
/在设置了cell.backgroundView的背景颜色同时,也设置了cell.backgroundColor

//此时cell.textLabel.text = @"textLabel";

//如果在cell.backgroundColor = [UIColor redColor];后面,

//则label的背景颜色将会与cell.backgroundColor一致,如果在之前,
//则不会影响到label的背景颜色

cell.backgroundColor = [UIColor redColor];

cell.textLabel.text = @"textLabel";
//设置cell右侧按钮样式
cell.accessoryType = UITableViewCellAccessoryDetailButton;
//自定义cell右侧控件,但需要自己添加监听方法
cell.accessoryView = btn;
/设置cell的选中样式
self.selectionStyle = UITableViewCellSelectionStyleNone;
 1 自定义Cell与重用

NSString *ID = @"contact_cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

if (cell == nil) { //用户不会执行下面的语句

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];

}

2. tableview中的静态cell被重用时,只与identifier的设置有关,与tableview 的Content无关,与cell的Style属性也无关。
3. 如果需要自定义cell,需要将style设置成Custom后,再自行拖拽控件
4. 自定义cell类时,需要自行创建一个UITableViewCell的子类,并设置cell的Class为这个子类,用这个子类来管理自定义的视图类,视图类通过Class关联了子类后,便可以进行连线管理了。

5 静态Cell

静态的Cell需要设置tableView的Content属性为Static Cells,然后再设置分组数量,再点击每个分组设置row

6我想把第一个cell显示的数据 向后缩进10个像素其他的cell不变怎么办呢

其实tableview已经给我提供了这样的函数

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row ==0) {

return10;

}

return
0;

}

iOS-UITableView的使用的更多相关文章

  1. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  2. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

  3. iOS UITableView Tips(2)

    #TableView Tips(2) (本来想一章就结束TableView Tips,但是发现自己还是太天真了~too young,too simple) ##架构上的优化 在Tips(1)中指出了一 ...

  4. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  5. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

  6. iOS UITableView 引起的崩溃问题

    其实 UITableView 应该是在iOS开发中使用最频繁的一个控件,一次同事之间聊天玩笑的说“一个页面,要是没使用UITableView,就好像称不上是一个页面”.虽然是个最常见的控件,但是他的强 ...

  7. IOS UITableView下拉刷新和上拉加载功能的实现

    在IOS开发中UITableView是非常常用的一个功能,而在使用UITableView的时候我们经常要用到下拉刷新和上拉加载的功能,今天花时间实现了简单的UITableView的下拉刷新和上拉加载功 ...

  8. iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)

    有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器 ...

  9. iOS:UITableView 方法 属性

    参考:https://developer.apple.com/library/iOS/documentation/UIKit/Reference/UITableView_Class/Reference ...

  10. iOS UITableView左滑操作功能的实现(iOS8-11)

    WeTest 导读 本文主要是介绍下iOS 11系统及iOS 11之前的系统在实现左滑操作功能上的区别,及如何自定义左滑的标题颜色.字体大小. 一.左滑操作功能实现 1.如果左滑的时候只有一个操作按钮 ...

随机推荐

  1. 15 Vue计算属性和侦听器

    计算属性 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的. 在模板中放入太多的逻辑会让模板过重且难以维护.例如: split = 字符中间空格分割, reverse= 反转 join('' ...

  2. splay 1296 营业额统计

    有一个点超时,确实是个很简单的splay#include<cstdio> #include<iostream> using namespace std; int n,shu[1 ...

  3. qt 在windows 以及android 运用资源时的路径使用用限制

    qt中存在以下几种路径的使用方式. 1.qrc内置资源在应用程序中属于只读的资源,作为应用程序的一部分,而不是在一个文件夹中与app分离.资源文件在.qrc文件中的路径如  <file>i ...

  4. fopen 的mode

    转自 http://blog.csdn.net/todd911/article/details/8976543 r 打开只读文件,该文件必须存在. r+具有读写属性,从文件头开始写,保留原文件中没有被 ...

  5. LOJ#2977. 「THUSCH 2017」巧克力(斯坦纳树+随机化)

    题目 题目 做法 考虑部分数据(颜色较少)的: 二分中位数\(mid\),将\(v[i]=1000+(v[i]>mid)\) 具体二分操作:然后求出包含\(K\)种颜色的联通快最小的权值和,判断 ...

  6. Linux下java环境变量配置

    安装步骤 1.查看当前Linux系统是否安装java rpm -qa | grep java 2.卸载系统中已经存在的openJDK rpm -e --nodeps java--openjdk-1.7 ...

  7. Java 单例设计模式之 饿汉式和懒汉式

    public class InstanceSampleTest { public static void main(String[] args) { /** 单例设计模式的 饿汉式和懒汉式 * 单例模 ...

  8. 【caffe编译】nvcc warning:The 'compute_20', 'sm_20'

    Makefile.config 中 CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \ -gencode arch=compute_20,code=s ...

  9. 我的BO之数据保护

    我的BO 1-我的BO之强类型 2-我的BO之数据保护 3-我的BO之状态控制 4-我的BO之导航属性 数据保护指什么 软件的运行离不开数据,数据一般存在对象中.这种对象在 Java 统称为 POJO ...

  10. Leetcode题 112 和 113. Path Sum I and II

    112题目如下: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addi ...