h文件

#import <UIKit/UIKit.h>

@interface ViewController :UIViewController<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) NSArray *dataList;

@property (nonatomic, retain) UITableView *myTableView;

@property (nonatomic, retain) NSDictionary *myDic;

@end

m文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad

{

[superviewDidLoad];

//初始化数据

NSArray *array1_=@[@"张铁林",@"张国立",@"张国荣",@"张艺谋",@"张惠妹"];

NSArray *array2_=@[@"李小龙",@"李小路",@"李苑苑",@"李明"];

NSArray *array3_=@[@"王刚",@"王力宏",@"王大拿",@"王萧",@"王萌萌",@"王营",@"王维"];

self.myDic=@{@"老张家":array1_,@"老李家":array2_,@"老王家":array3_};

UITableView *myTableView_=[[UITableViewalloc] initWithFrame:CGRectMake(0,20, 320,460) style:UITableViewStylePlain];

myTableView_.delegate=self;

myTableView_.dataSource=self;

//改变换行线颜色lyttzx.com

myTableView_.separatorColor = [UIColorblueColor];

//设定Header的高度,

myTableView_.sectionHeaderHeight=50;

//设定footer的高度,

myTableView_.sectionFooterHeight=1000;

//设定行高

myTableView_.rowHeight=100;

//设定cell分行线的样式,默认为UITableViewCellSeparatorStyleSingleLine

[myTableView_ setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

//设定cell分行线颜色

[myTableView_ setSeparatorColor:[UIColorredColor]];

//编辑tableView

myTableView_.editing=NO;

[self.view addSubview:myTableView_];

//跳到指的row or section

[myTableView_ scrollToRowAtIndexPath:[NSIndexPathindexPathForRow:2inSection:2]  atScrollPosition:UITableViewScrollPositionBottomanimated:NO];

}

//指定有多少个分区(Section),默认为1

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

return [[self.myDicallKeys] count];

}

//每个section底部标题高度(实现这个代理方法后前面 sectionHeaderHeight设定的高度无效)

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

return 15;

}

//每个section头部标题高度(实现这个代理方法后前面 sectionFooterHeight设定的高度无效)

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

return 20;

}

//每个section头部的标题-Header

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

return [[self.myDicallKeys] objectAtIndex:section];

}

//每个section底部的标题-Footer

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

return nil;

}

//用以定制自定义的section头部视图-Header

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

return nil;

}

//用以定制自定义的section底部视图-Footer

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

UIImageView *imageView_=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 320, 20)];

imageView_.image=[UIImageimageNamed:@"1000.png"];

//return [imageView_ autorelease];

return imageView_;

}

//指定每个分区中有多少行,默认为1

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

return [[self.myDicobjectForKey:[[self.myDicallKeys]objectAtIndex:section]] count];

}

//改变行的高度(实现主个代理方法后 rowHeight设定的高度无效)

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

return 100;

}

//绘制Cell

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

static NSString *SimpleTableIdentifier =@"SimpleTableIdentifier";

UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:

SimpleTableIdentifier];

if (cell == nil) {

cell = [[UITableViewCellalloc] initWithStyle: UITableViewCellStyleDefaultreuseIdentifier: SimpleTableIdentifier];

//设定附加视图

[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];

//        UITableViewCellAccessoryNone,                   //没有标示

//        UITableViewCellAccessoryDisclosureIndicator,    //下一层标示

//        UITableViewCellAccessoryDetailDisclosureButton, //详情button

//        UITableViewCellAccessoryCheckmark               //勾选标记

//设定选中cell时的cell的背影颜色

cell.selectionStyle=UITableViewCellSelectionStyleBlue;    //选中时蓝色效果

//        cell.selectionStyle=UITableViewCellSelectionStyleNone; //选中时没有颜色效果

//        cell.selectionStyle=UITableViewCellSelectionStyleGray;  //选中时灰色效果

//

//        //自定义选中cell时的背景颜色

//        UIView *selectedView = [[UIView alloc] initWithFrame:cell.contentView.frame];

//        selectedView.backgroundColor = [UIColor orangeColor];

//        cell.selectedBackgroundView = selectedView;

//        [selectedView release];

//        cell.selectionStyle=UITableViewCellAccessoryNone; //行不能被选中

}

//这是设置没选中之前的背景颜色

cell.contentView.backgroundColor = [UIColorclearColor];

cell.imageView.image=[UIImageimageNamed:@"1000.jpg"];//未选cell时的图片

cell.imageView.highlightedImage=[UIImageimageNamed:@"1001.jpg"];//选中cell后的图片

cell.textLabel.text=[[self.myDicobjectForKey:[[self.myDicallKeys]objectAtIndex:indexPath.section]]objectAtIndex:indexPath.row];

return cell;

}

//行缩进

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

NSUInteger row = [indexPath row];

return 0*row;

}

//选中Cell响应事件

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

[tableView deselectRowAtIndexPath:indexPathanimated:YES];//选中后的反显颜色即刻消失

//得到当前选中的cell

UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];

NSLog(@"选中cell=%@",cell.textLabel.text);

}

//行将显示的时候调用,预加载行

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

NSString *s = cell.textLabel.text;

NSInteger i = [indexPath  row];

NSLog(@"将要显示的行是\t cell=%@  \t indexpath=%d",s,i);

}

//选中之前执行,判断选中的行(阻止选中第一行)

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSUInteger row = [indexPath row];

if (row == 0)

return nil;

return indexPath;

}

//编辑状态,点击删除时调用

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle

forRowAtIndexPath:(NSIndexPath *)indexPath

{

}

//cell右边按钮格式为UITableViewCellAccessoryDetailDisclosureButton时,点击按扭时调用的方法

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

NSLog(@"当前点击的详情button \t indexpath=%@",indexPath);

}

//右侧添加一个索引表

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

return [self.myDicallKeys];

}

//划动cell是否出现del按钮

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

return YES;

}

//设定横向滑动时是否出现删除按扭,(阻止第一行出现)

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

{

if (indexPath.row==0) {

returnUITableViewCellEditingStyleNone;

}

else{

returnUITableViewCellEditingStyleDelete;

}

returnUITableViewCellEditingStyleDelete;

}

//自定义划动时delete按钮内容

- (NSString *)tableView:(UITableView *)tableView

titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{

return@"删除这行";

}

//开始移动row时执行

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

{

NSLog(@"sourceIndexPath=%@",sourceIndexPath);

NSLog(@"sourceIndexPath=%@",destinationIndexPath);

}

//滑动可以编辑时执行

-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

NSLog(@"willBeginEditingRowAtIndexPath");

}

//将取消选中时执行, 也就是上次先中的行

-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSLog(@"上次选中的行是  \n indexpath=%@",indexPath);

return indexPath;

}

//让行可以移动

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

return NO;

}

//移动row时执行

-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath

{

NSLog(@"targetIndexPathForMoveFromRowAtIndexPath");

//用于限制只在当前section下面才可以移动

if(sourceIndexPath.section != proposedDestinationIndexPath.section){

return sourceIndexPath;

}

return proposedDestinationIndexPath;

}

@end

UITableView 部分方法详解相关推荐

  1. Protocol与Delegate 使用方法详解

    你要知道的KVC.KVO.Delegate.Notification都在这里 转载请注明出处 http://blog.csdn.net/u014205968/article/details/78224 ...

  2. python统计csv行数_对Python 多线程统计所有csv文件的行数方法详解

    如下所示: #统计某文件夹下的所有csv文件的行数(多线程) import threading import csv import os class MyThreadLine(threading.Th ...

  3. python修改文件内容_Python批量修改文本文件内容的方法详解

    这篇文章主要介绍了Python批量修改文本文件内容的方法的相关资料,需要的朋友可以参考下 Python批量替换文件内容,支持嵌套文件夹 import os path="./" fo ...

  4. python二维元组_python中读入二维csv格式的表格方法详解(以元组/列表形式表示)

    如何去读取一个没有表头的二维csv文件(如下图所示)? 并以元组的形式表现数据: ((1.0, 0.0, 3.0, 180.0), (2.0, 0.0, 2.0, 180.0), (3.0, 0.0, ...

  5. Spring JdbcTemplate方法详解

    2019独角兽企业重金招聘Python工程师标准>>> Spring JdbcTemplate方法详解 标签: springhsqldbjava存储数据库相关sql 2012-07- ...

  6. golang 解析php序列化,golang实现php里的serialize()和unserialize()序列和反序列方法详解...

    Golang 实现 PHP里的 serialize() . unserialize() 安装 go get -u github.com/techleeone/gophp/serialize 用法 pa ...

  7. ES5和ES6数组遍历方法详解

    ES5和ES6数组遍历方法详解 在ES5中常用的10种数组遍历方法: 1.原始的for循环语句 2.Array.prototype.forEach数组对象内置方法 3.Array.prototype. ...

  8. linux expect 输入密码,shell脚本无密码登录 expect的使用方法详解

    shell脚本无密码登录 expect的使用方法详解 今天需要做一个定时任务脚本将最新的数据包文件传到远程的服务器上,虽然有密钥但也是要求输入密码的那种,所以只能另想办法实现让脚本自动输入密码了. 从 ...

  9. 饥荒怎么自动订阅服务器,饥荒联机版自动挂礼物mod及使用方法详解

    饥荒联机版中官方经常会推出一些挂机掉落礼物的活动,可能一些玩家会觉得很麻烦,下面给大家分享一些自动挂礼物mod和其使用方法,希望可以帮助到各位玩家. 饥荒联机版自动挂礼物mod及使用方法详解 挂礼物m ...

  10. linux oracle 用户创建,LINUX下Oracle数据库用户创建方法详解

    本文实例分析了LINUX下Oracle数据库用户创建方法.分享给大家供大家参考,具体如下: 1)登录linux,以oracle用户登录(如果是root用户登录的,登录后用 su - oracle命令切 ...

最新文章

  1. 「功能笔记」Spacemacs+Evil备忘录
  2. P4148 简单题(KDTree)
  3. lamp mysql开机自启_centos下设置自启动和配置环境变量的方法
  4. 训练日志 2018.9.29
  5. 计算机能实现哪些人类智力活动,人工智能是电脑科学的一个重要分支,它的近期目标是什么?...
  6. pip安装wxpython报错_Ubuntu 上搭建robotframework
  7. Ajax异步获取html数据中包含js方法无效的解决方法
  8. asp.net获取浏览器的唯一标识_vue单页面应用如何在微信浏览器里进行网页授权获取用户信息
  9. 快速破解rar解压密码
  10. 特种作业人员题库及答案
  11. MODIS R包下载数据
  12. 用Android studio 做出QQ登录界面
  13. CS代理+proxychains+nmap进行内网扫描
  14. react源码分析:babel如何解析jsx
  15. 人工智能数学基础:泰勒(Taylor)公式
  16. 小功率机械无级变速器结构设计
  17. 闲扯Maven项目代码组织形式
  18. 跟踪信号发生器如何产生宽频带信号?
  19. python常用的集成开发工具,python的主流开发工具
  20. printf及无符号型整数

热门文章

  1. 经验分享:利用树莓派开发板制作无线路由器
  2. zanti html恶搞,Html.AntiForgeryToken 突然报这个错误 太奇怪了
  3. Linux proc目录详解
  4. CAD打断曲线(com接口c#语言)
  5. Python刷题系列(8)_Pandas_Dataframe
  6. KEIL识别不出野火STM32仿真器问题解决
  7. 迪杰斯算法c语言,欧博体育APP-欧博体育APP
  8. HeadFirst 设计模式 4工厂模式(披萨店演变)
  9. 如何清除电脑桌面图标蓝底
  10. 自动驾驶之-MATLAB环境下基于深度学习的语义分割