- (void)viewDidLoad {

[super viewDidLoad];

self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStyleGrouped];分组形式的

self.myTableView.delegate = self;

self.myTableView.dataSource = self;     <UITableViewDelegate,UITableViewDataSource>两个代理都要遵守

self.myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;     分割线

[self.myTableView setEditing:YES];     编辑状态

[self.view addSubview:_myTableView];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 26;

}

2.有多少行,调用多次

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

if ((section+1)%2 == 0) {

return 3;

}else{

return 2;

}

}

3.某段某行显示什么样子  NSIndexPath封装的两个属性section和row

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

//重复利用机制

NSString *cellID = @"cellID";

//先判断是否有可以重复利用的cell

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell==nil) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

}

//cell显示的样式

cell.textLabel.text = [NSString stringWithFormat:@"%ld,%ld",indexPath.section,indexPath.row];

return cell;

}

4.配置cell高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 80;

}

5.段落头部尾部

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

return @"头标题";

}

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

return @"尾标题";

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

return 30;

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

return 30;//不能没有,如果想没有就把值变小

}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

UIView * v =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];

v.backgroundColor = [UIColor redColor];

return v;

}

6.cell被点了要做什么

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[tableView deselectRowAtIndexPath:indexPath animated:YES];取消点击事件

}

7.设置cell是否可以编辑

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{

if (indexPath.row== 0) {

return NO;

}else{

return YES;

}

}

8.更改编辑状态的按钮

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

return  UITableViewCellEditingStyleDelete;

}

9.更改删除状态下右边显示的标题

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{

return @"删除";

}

10.删除状态下按钮被点

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

}

11.cell可以上下移动

-(bool)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

return YES;

}

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

}

12.索引标题

-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{

NSMutableArray * titleArray = [NSMutableArray array];

for (int i = 0; i<26; i++) {

[titleArray addObject:[NSString stringWithFormat:@"%c",'A'+i]];

}

return titleArray;

}

12 滚动到最后一行

QQ会话中总是希望添加一行就向上滚动总是显示最新的消息

NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:_messageArray.count-1 inSection:0];记录最下面的行的位置

[self.QQTalkTableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];滚到哪里

13 有新数据时加载数据

[self.myTalkTableView reloadData];

有很多种刷新,视具体情况而定

0301——UItableView的更多相关文章

  1. iOS UITableView 与 UITableViewController

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

  2. UITableView(二)

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  3. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  4. iOS 编辑UITableView(根据iOS编程编写)

    上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为  e ...

  5. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

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

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

  7. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  8. UITableview delegate dataSource调用探究

    UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...

  9. UITableView点击每个Cell,Cell的子内容的收放

    关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...

随机推荐

  1. iOS9新特性之UIStackView

    同iOS以往每个迭代一样,iOS 9带来了很多新特性.UIKit框架每个版本都在改变,而在iOS 9比较特别的是UIStackView,它将从根本上改变开发者在iOS上创建用户界面的方式.本文将带你学 ...

  2. 22 java常用方法

    /** * 通过正则获取该目录下满足条件的所有目录 * @param luceneFilePathRegular 正则目录,如/user/solrindex/正则表达式 * @return 满足正则表 ...

  3. C语言初学 比较五个整数并输出最大值和最小值1

    #include<stdio.h> #include<math.h> int max(int x,int y) { if(x>y) return x; else retu ...

  4. Linux/Unix工具与正则表达式的POSIX规范

    http://www.infoq.com/cn/news/2011/07/regular-expressions-6-POSIX 对正则表达式有基本了解的读者,一定不会陌生『\d』.『[a-z]+』之 ...

  5. MySQL 学习笔记 (范式)

    范式基本就是不要有重复的数据,表和表之间都是用主键和外键来联系 表的关系通常分3中 1 对 1 1 对 多 多 对 多 多 对 多 是用另一个表来实现的,这个表记入了a 表和 b表之间多对多的联系主键

  6. 如何在Protel99se中批量修改元件的封装

    有时候需要批量修改元件的封装,可在原理图和PCB中批量修改.本文以批量修改电阻AXIAL0.3 的封装为AXIAL0.4 为例. 1. 在原理图中批量修改1.1. 方法1双击需要修改封装的其中一个元件 ...

  7. 树莓派入门教程——使用Qt开发界面程序

    前言        Qt是一个1991年由奇趣科技开发的跨平台C++图形用户界面应用程序开发框架.它既可以开发GUI程序,也可用于开发非GUI程序,比如控制台工具和服务器.Qt是面向对象的框架,使用特 ...

  8. 一些pyhon的学习资料

    一直没有时间学习python,都说python语法简洁优美.但是我看它的语法还是不爽啊,没C/C++好阅读.但是C/C++又必须了解底层的计算机模型.着实会门槛高一些.特别是C++,对于我来说简直就是 ...

  9. codility上的问题 (23)Chi 2012

    这个题也比较有意思.意思是给定一个数组A,长度为M,里面都是正整数,代表每块地形的高度.现在要测试一种加农炮,给定一个炮弹的高度H, 如果存在最小的I,满足0 < I <  M,满足A[I ...

  10. 【转】putty基本操作--不错

    原文网址:http://www.cnblogs.com/skynext/p/3256035.html putty基本操作 1,进入全屏 标题栏右键,菜单中就有full screen选项. 2,退出全屏 ...