UITableView详细注释

style

 //普通
  UITableViewStylePlain,
 //分组
  UITableViewStyleGrouped

//表格视图
    UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    //设置数据源
    tableView.dataSource = self;
    //设置代理
    tableView.delegate = self;
    //分区头的高度
    tableView.sectionHeaderHeight = 30;
    //分区尾的高度
    tableView.sectionFooterHeight = 30;

    //行高,默认行高是44。
//    tableView.rowHeight = 100;
//    tableView.backgroundColor = [UIColor grayColor];

/*

         UITableViewCellSeparatorStyleNone 没有线
         UITableViewCellSeparatorStyleSingleLine  单行线
         UITableViewCellSeparatorStyleSingleLineEtched  被石化的单行线

        //线的风格
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//        _tableView.separatorColor = [UIColor redColor];
        //线的内边距
        _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

//行高固定时使用
        _tableView.rowHeight = 60;

    //设置背景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 = 100;
        //选择索引时的背景颜色
        _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;
}
时间: 2024-08-10 21:29:03

UITableView详细注释的相关文章

Qt5_简易画板_详细注释

代码下载链接:  http://pan.baidu.com/s/1hsc41Ek 密码: 5hdg 显示效果如下: 代码附有详细注释(代码如下) 1 /*** 2 * 先新建QMainWindow, 项目名称: DrawWidget 基类选择: QMainWindow, 3 * 类名默认, 然后在DrawWidget项目名上新建c++class文件, 选择基类: QWidget 4 */ 5 //先完成绘图区的实现 6 //如下为: drawwidget.h 7 #ifndef DRAWWIDG

codevs 2924 数独挑战 x(三种做法+超详细注释~)

2924 数独挑战 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 钻石 Diamond 题目描述 Description “芬兰数学家因卡拉,花费3个月时间设计出了世界上迄今难度最大的数独游戏,而且它只有一个答案.因卡拉说只有思考能力最快.头脑最聪明的人才能破解这个游戏.”这是英国<每日邮报>2012年6月30日的一篇报道.这个号称“世界最难数独”的“超级游戏”,却被扬州一位69岁的农民花三天时间解了出来. 看到这个新闻后,我激动不已,证明我们OI的实力的机会来了,我们虽然不是

多线程实现生产者消费者问题 详细注释 事件+临界区 信号量+临界区2种方法

生产者消费者问题:  该问题描述了两个共享固定大小缓冲区的线程--即所谓的"生产者"和"消费者"--在实际运行时会发生的问题.生产者的主要作用是生成一定量的数据放到缓冲区中,然后重复此过程.与此同时,消费者也在缓冲区消耗这些数据.该问题的关键就是要保证生产者不会在缓冲区满时加入数据,消费者也不会在缓冲区中空时消耗数据.具体我就不解释了   应该都懂 不懂请百度一下 我是用事件实现生产者消费者问题的同步  用临界区实现互斥    我的这个做法与经典做法不同 即用信号量

30多个iOS常用动画,带详细注释

// //  CoreAnimationEffect.h //  CoreAnimationEffect // //  Created by VincentXue on 13-1-19. //  Copyright (c) 2013年 VincentXue. All rights reserved. // #import <Foundation/Foundation.h> /**  !  导入QuartzCore.framework  *  *  Example:  *  *  Step.1

ABP+Zero+Metronic+Redis的完美结合快速启动模板(超级代码详细注释版本)

微信扫一扫并支付成功,联系QQ:770628656获取所有源码(超级代码详细注释版本) 原文地址:https://www.cnblogs.com/abpbasic/p/8124792.html

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

 原题链接   无向连通图中,如果删除某边后,图变成不连通,则称该边为桥. 也可以先用Tajan()进行dfs算出所有点 的low和dfn值,并记录dfs过程中每个 点的父节点:然后再把所有点遍历一遍, 看其low和dfn,满足dfn[ fa ]<low[ i ](0<i<=n, i 的 father为fa) -- 则桥为fa-i. 找桥的时候,要注意看有没有重边:有重边,则不是桥. 另外,本题的题意及测试样例中没有重边,所以不用考虑重边. 带详细注释的题解: #include<s

降水量与蒸发量统计报表详细注释

//降水量与蒸发量统计报表详细注释 <template> <div id="main" :style="{width:'1000px',height:'500px' }"></div> </template> <!--1 为ECharts准备一个具备大小(宽高)的Dom--> <!-- <div id="mainBar" style="height:500px;bo

SAP CRM BOL编程基础,代码+详细注释

网络上可以找到一些使用BOL查询.维护数据的DEMO,但几乎都是单纯的代码,缺乏说明,难以理解.本文除了代码外,还给出了详细的注释,有助于理解BOL编程中的一些基本概念. 这是一篇翻译的文章,你可能会发现部分内容不是很好理解,这时可以直接阅读原文. 原文所在的sapcrmwebui.com是一个不错的博客,然而网站不是很稳定,偶尔会连接不上,建议使用Internet Archive访问. 如果你访问不了Internet Archive,说明你需要一点过墙的手段. 本文链接:http://www.

【转】IOS 30多个iOS常用动画,带详细注释

原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 // //  CoreAnimationEffect.h //  CoreAnimationEffect // //  Created by VincentXue on 13-1-19. //  Copyright (c) 2013年 VincentXue. All rights reserved. // #import <Foundation/Foundation.h>