1、UITableView 表格视图

服从数据源 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {}返回的视图推不上去

但是tableHeaderView 可以推上去

UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

//普通

UITableViewStylePlain,

//分组

UITableViewStyleGrouped

//设置数据源

tableView.dataSource = self;

//设置代理

tableView.delegate = self;

//得到所有选中的行数

[self.tableView indexPathsForSelectedRows];

//分区头的高度 默认20

tableView.sectionHeaderHeight = 30;

//分区尾的高度 默认20

tableView.sectionFooterHeight = 30;

//行高,默认行高是44。

tableView.rowHeight = 100;

tableView.backgroundColor = [UIColor grayColor];

//设置背景View

UIImageView * imageView = [[UIImageView alloc] initWithFrame:tableView.bounds];

imageView.image = [UIImage imageNamed:@"baby.jpg"];

tableView.backgroundView = imageView;

//取消选中某一行

[tableView deselectRowAtIndexPath:indexPath animated:YES];

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

//线的风格

_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

//线的内边距

_tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

//索引区域的背景

_tableView.sectionIndexBackgroundColor = [UIColor whiteColor];

//设置索引文字的颜色

_tableView.sectionIndexColor = [UIColor blueColor];

//cell行数小于多少是展示索引

_tableView.sectionIndexMinimumDisplayRowCount = 100;

//选择索引时的背景颜色

_tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];

//显示索引的题目

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

return [self.dataList valueForKey:@"title”];

 
2、UITableViewCell

sep//设置单元格文本

cell.textLabel.text = wechat.title;

//设置单元格 左边视图

cell.imageView.image = [UIImage imageNamed:wechat.icon];

//选中风格

UITableViewCellSelectionStyleNone, //没有点中效果

UITableViewCellSelectionStyleBlue, ==

UITableViewCellSelectionStyleGray, ==

UITableViewCellSelectionStyleDefault

cell.selectionStyle = UITableViewCellSelectionStyleDefault;

//设置cell右端图标

UITableViewCellAccessoryDisclosureIndicator 尖角号

UITableViewCellAccessoryDetailDisclosureButton 圆圈感叹号加尖角号

UITableViewCellAccessoryCheckmark 对号

UITableViewCellAccessoryDetailButton 圆圈感叹号

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

//UITableViewCellStyle 单元格风格

UITableViewCellStyleDefault  显示图片,显示辅助图片,显示一行文字

UITableViewCellStyleValue1   显示图片,显示辅助图片,普通文字,描述文字,共占一排

UITableViewCellStyleValue2   不显示图片,显示辅助图片,普通文字,描述文字,共占一排

UITableViewCellStyleSubtitle 显示图片,显示辅助图片,普通文字,描述文字,共占两排

//设置描述文字

cell.detailTextLabel.text = industry.state;

 
//UITableViewCell 复用机制

static NSString * identifier = @"cellID";

//从复用池里找对应的cell

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (!cell) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellID"];

}

3、UITableViewDataSource 数据源

//cell单元格,IndexPath索引  UITableViewCell是组成UITableView的单元格

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

//Section是几组,Rows多少行(每组内有多少元素),默认情况下只有一个Section.分组的index为0(每一分组多少行)

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

//返回分区顶部标题

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

//返回分区尾部标题

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

//返回单元格的组数

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

//返回表格视图是否可以编辑

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

//返回表格视图是否可以滚动

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

4、UITableViewDelegate 代理方法

//选中某一行

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

//设置分区头部视图

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

//设置分区尾部视图

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

//当滚动表格时,这个代理方法,一直调用

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

//设置行高方法,如果实现这个代理方法,rowHeight无效,这个主要用于设置可变cell高度

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

return 100;

}

//修改左侧滑动删除方法

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

iOS - UI - UITableView的更多相关文章

  1. [IOS]IOS UI指南

    [IOS]IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻 ...

  2. iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath(汇总)

    iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath 首先分析有几种原因,以及相应的解决方法 1.UITableViewCell的userInterac ...

  3. IOS UI 第八篇:基本UI

    实现图片的滚动,并且自动停止在每张图片上     - (void)viewDidLoad{    [super viewDidLoad]; UIScrollView *scrollView = [[U ...

  4. 国外IOS UI指南

    国外IOS UI指南 众所周知,IOS的界面设计,越来越流行,可以说都形成了一个标准,搜集了一些资料,供自己以后学习使用! iOS Human Interface Guidelines (中文翻译) ...

  5. iOS UI的几种模式

    iOS UI的几种模式: 1.平凡模式(原生控件组合): 2.新闻模式: 3.播放器模式: 4.微博模式:

  6. 通过实现一个TableView来理解iOS UI编程

    推荐一篇神作: 通过实现一个TableView来理解iOS UI编程 http://blog.jobbole.com/61101/

  7. iOS programming UITableView and UITableViewController

    iOS programming  UITableView and UITableViewController A UITableView displays a single column of dat ...

  8. IOS之UI -- UITableView -- 1 -- 相关初识

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  9. IOS UI 第九篇: UITABLEVIEW

    学英语.所以用英文来记录笔记.   Define the dataSource:   @implementation ViewController{    NSMutableArray *dataSo ...

随机推荐

  1. 如何在协作开发安卓项目中打jar包给合作人

    一般情况下,id都是安卓自动生成的.使用时只要用R.id.xx就可以了.但是,在合作开发安卓时,需要将自己开发的代码部分打成jar包,甚至做混淆. 这就需要使用java的反射机制.在取id时使用如下类 ...

  2. IOS深入学习(19)之View object

    1 前言 本章主要介绍了View视图对象,包括了其属性,视图间关系和CALayer的简介. 英文原文:http://blog.csdn.net/developer_zhang/article/deta ...

  3. session与缓存

    分布式系统开发常见问题-1. session的复制与共享 2. 分布式缓存的设计 1. session的复制与共享 在web应用中,为了应对大规模访问,必须实现应用的集群部署.要实现集群部署主要需要实 ...

  4. 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.1 Index用户列表]

    3.1 Index用户列表 或许当前域下的用户列表 [Authorize] public async Task<ActionResult> Index() { var userList = ...

  5. Oracle中TO_DATE格式

    转自:http://www.cnblogs.com/ajian/archive/2009/03/25/1421063.html TO_DATE格式(以时间:2007-11-02   13:45:25为 ...

  6. easyui grid中翻页多选方法

    <table class="easyui-datagrid" title="人员选择" id="dg" data-options=&q ...

  7. (C++)String的用法

    (转自http://www.cnblogs.com/yxnchinahlj/archive/2011/02/12/1952550.html) 之所以抛弃char*的字符串而选用C++标准程序库中的st ...

  8. 使用jQuery-AJAX–读取获得跨域JSONP数据的示例

    在项目开发中,如果在同一个域名下就不存在跨域情况,使用$.getJSON()即可实现.但是需要跨域请求其他域名下面的Json数据就需要JSONP的方式去请求,跨域写法和getJSON有差异.如下:   ...

  9. phantomjs

    PhantomJS是以WebKit为核心并提供JavaScript编程接口(API)的无界面浏览器. 它提供对web标准的 快速 并且 原生 的支持: DOM操作.CSS选择符.JSON.Canvas ...

  10. C语言综述

    1.预处理指令:在变异之前执行的指令. 系统自带的文件用<>,自己写的文件用""; .h成为头文件,用来声明一些常用的函数,假如想使用这些函数,就必须包含这个头文件(注 ...