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. Ubuntu 安装 Redis

    1. 下载并安装 redis 2.6.16版 sudo mkdir /usr/local/src/Redis cd /usr/local/src/Redis sudo wget http://down ...

  2. Disney English

    项目大体流程是做几个页面的模板,然后后台用html改成phtml 但是后期连模板都要改掉,很多都无法考虑到复用 css很混乱,js已经忘记了

  3. Eclipse管理Java工程(j2se/j2ee/maven)

    Eclipse管理J2SE/J2EE(Maven)项目 eclipse是一个集成开发工具,有编译,运行,打包部署等功能.eclipse可以新建多种项目,不同的项目有不同的IDE层次结构,方便用户管理资 ...

  4. Linux内核简介

    内核是提供硬件抽象层.磁盘及文件系统控制.多任务等功能的系统软件.一个内核不是一套完整的操作系统.一套基于Linux内核的完整操作系统叫作Linux操作系统,或是GNU/Linux.Linux内核的主 ...

  5. java synchronized类锁,对象锁详解(转载)

    觉得还不错 留个记录,转载自http://zhh9106.iteye.com/blog/2151791 在java编程中,经常需要用到同步,而用得最多的也许是synchronized关键字了,下面看看 ...

  6. json2.js 使用

    参考:http://www.cnblogs.com/youring2/archive/2013/03/01/2938850.html github地址:https://github.com/dougl ...

  7. for循环的嵌套——7月24日

      练习一:输入一个正整数,用for循环嵌套求阶乘的和 //输入一个正整数,求1!+2!+....+n! 用for循环嵌套 Console.Write("请输入一个正整数:"); ...

  8. 有一种感动叫ACM(记WJMZBMR在成都赛区开幕式上的讲话)

    各位选手,各位教练,大家好,我是来自清华大学交叉信息学院的陈立杰,今天很荣幸站在这里代表全体参赛选手发言.对于我来说,这是我第一次正式参加ACM的比赛.不过我跟ACM之间的缘分,大概在很早的时候就已经 ...

  9. linq.js

    在做后台开发的时候,总是会碰到将拿到手的数据进行条件校验,而这些数据又不仅仅是单纯的一个,有时候会是一串大数据,需要自己在后台处理进而展示到前台页面上,酱紫自己第一反应就是使用for循环来遍历,并把所 ...

  10. 如何对ConnectionString进行加密解码?

    这个就不说了就是一个类 public static class EncryptionConfig { /* 加密配置节点 * Response.Write(EncryptionConfig.Encry ...