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. UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)

    题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...

  2. jQuery在updatepanel中使用造成内存泄露

    wijmo用户反馈了一个RadialGauge控件内存泄露的bug,采用chrome监控内存使用情况,发现明显的内存泄露,在前面的文章中我就发现了jQuery内存泄露的问题,这次再次发现此问题,自然就 ...

  3. 解决ie6不支持position: fixed;导致无法滚动的办法

    <div id="im" style="top: 100px; position: fixed; left: 5px; border: 3px solid #006 ...

  4. erlang 查看进程相关信息

    出自: http://blog.sina.com.cn/s/blog_96b8a1540100zczz.html

  5. cocos2dx Http网络编程

    转自:http://blog.csdn.net/wangbin_jxust/article/details/9632771,http://blog.csdn.net/wangbin_jxust/art ...

  6. CentOS 6.5 源码安装MySQL5.6

    1:下载安装cmake (mysql5.5以后是通过cmake来编译的) #http://download.csdn.net/detail/csxuedn/7976005 #wget http://w ...

  7. 我的javascript学习之路(一)对象之基础

    做了2个多月的ajax项目,对js的学习觉得了深入了不少,把自己的一些学习的经验贴出来,希望对初学者有所帮助,也希望大家能指出我的错误之处或者不当之处. javascript 是基于对象的语言,为什么 ...

  8. C#调用C++ dll时,结构体引用传参的方法

    写了一个C++的LogLog Logit 四参数等算法的接口dll,给C#调用,但是发现传参有问题 如 extern "C" _declspec(dllexport)  bool ...

  9. 应该把script标签放在哪里

    应该把script标签放在哪里 目录: 1script标签放在底部的好处 2应该放在底部的哪里   概述: 如果在页面中写JS的话,那必然会用到script标签,理论上script标签放在哪里都是可以 ...

  10. HTML <base> 标签

    定义和用法 <base> 标签为页面上的所有链接规定默认地址或默认目标. 通常情况下,浏览器会从当前文档的 URL 中提取相应的元素来填写相对 URL 中的空白. 使用 <base& ...