UITableView也有自己的代理协议,它本身继承自UIScrollView

一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法:

1.改变某一行的行高:(返回是某一索引的行高)

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

执行完毕后,会使得偶数行的行高为60,奇数行为100;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

(后面会用到)

// Called after the user changes the selection.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
NS_AVAILABLE_IOS(3_0);

二:UITableView的常用属性

1、可以用连线的方式设置数据源和代

self.tableView.dataSource

self.tableView.delegate

2、设置行高

self.tableView.rowHeight = 60;

@property (nonatomic) CGFloat rowHeight; //default value if unset

@property (nonatomic) CGFloat sectionHeaderHeight// default value if unset

@property (nonatomic) CGFloat sectionFooterHeight// default value if unset

3、设置分割线

1).separatorInset属性:

是设定分割线的上左下右的间距的属性,具体代码和效果如下

self.tableView.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);

self.tableView.separatorColor = [UIColor blackColor];

self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

self.tableView.separatorColor = [UIColor blackColor];

2).设置分割线风格
@property(nonatomic) UITableViewCellSeparatorStyle ;

4、设置tableView是否分组(默认在storyboard中已经设置) @property (nonatomic, readonly) UITableViewStyle

            UITableViewStylePlain,
UITableViewStyleGrouped
*separatorColor;
style;

5、自定义头和尾部

1)设置头
@property(nonatomic,retain) UIView *tableHeaderView;

//above row content. default is nil. not to be confused with section header

//给头加一个ContactAdd的按钮

self.tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd];

效果

@property(nonatomic,retain) UIView *tableFooterView;
//content. default is nil. not to be confused with section footer

12-27 UITableView常用属性及方法的更多相关文章

  1. UITableView常用属性和方法 - 永不退缩的小白菜

    UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00  博客园精华区原文  http://www.cnblogs.com/zhaofucheng11 ...

  2. ios基础篇(四)——UILabel的常用属性及方法

    UILabel的常用属性及方法:1.text //设置和读取文本内容,默认为nil label.text = @”文本信息”; //设置内容 NSLog(@”%@”, label.text); //读 ...

  3. SVG DOM常用属性和方法介绍(1)

    12.2  SVG DOM常用属性和方法介绍 将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析 ...

  4. 第190天:js---String常用属性和方法(最全)

    String常用属性和方法 一.string对象构造函数 /*string对象构造函数*/ console.log('字符串即对象');//字符串即对象 //传统方式 - 背后会自动将其转换成对象 / ...

  5. JavaScript中Number常用属性和方法

    title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...

  6. UIScrollView,UICollectionView 和UITableView的属性和方法

    UIScrollView,UICollectionView 和UITableView 三者之间的关系:UIScrollView是 UICollectionView 和 UITableView 的父类. ...

  7. Node.js process 模块常用属性和方法

    Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...

  8. UIView的一些常用属性和方法

    UIView的一些常用属性和方法 1. UIView的属性 UIView继承自UIResponder,拥有touches方法. - (instancetype)initWithFrame:(CGRec ...

  9. UIView常用属性与方法/UIKit继承结构

    UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...

随机推荐

  1. 能源项目xml文件标签释义--<context:component-scan>

    <context:component-scan base-package="com.xindatai.ibs" use-default-filters="false ...

  2. JavaScript 3D图表

    在说3D图表以前,首先要明确两个概念,一个是数据的维度,一个是呈现数据载体的维度.对于数据的维度,一维的数据呈现,但是呈现的载体是二维的平面图,比如饼图: 已经能够很清晰地观察到数据的分布情况.数据如 ...

  3. Combination Sum [LeetCode]

    Problem Description: http://oj.leetcode.com/problems/combination-sum/ Basic idea: It seems complicat ...

  4. Git从远程分支创建本地分支

    git fetch origin master:temp 这句命令的意思是:将远程origin仓库的master分支下载到本地,并新建一个分支temp.

  5. centos 5.8 64位系统安装 mysql5.6

    mysql5.5以上的版本编译需要 cmake         1 .安装cmake wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.g ...

  6. 创建link server链接服务器碰到的问题及解决办法

    问题描述 今天在做数据库迁移,然后新建link server(链接服务器)的时候,碰到以下问题. 我的sql 脚本是这样的. 然后,执行的时候就收到以下错误信息. Msg 468, Level 16, ...

  7. 如何管理好项目的DLL

    .net fx自带的dll net fx自带的dll,直接添加,注意.net fx版本即可. 第三方类库 如果是第三方类库,使用NuGet从NuGet官网下载,比如json.net,jQuery等. ...

  8. 使用Linq快速的操作XML

    开始内容之前先分享一段话 有时候,当你知道要做什么的时候就做的很快,比如你要实现个功能,码字的活儿不算很难,做个检索也不会有什么难倒你的.但是,做着做着,你发现好像世界上的工作都在重复,于是你有种心要 ...

  9. java面向对象编程--第十一章 异常处理

    1.异常:描述出错信息的对象. 字节码校验时,如发生错误,则会抛出异常. 2.所有异常的父类是Exception,异常可以捕获,可以处理. 所有错误的父类是Error,错误可以捕获,但不能处理. Th ...

  10. 胡扯两句——CDQ分治

    之前听大神讲过CDQ分治大概是个什么东西,但是一直还没有真正去搞过.今天稍微看了一下,写点自己的理解. 首先CDQ分治有两个条件. 条件1:可以分成两个独立互不影响的问题(这里的"独立&qu ...