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. RESEACH PAPER

      个,proquest的username和password赫然在目,别急,再看第4个结 果"HB Thompson Subscription Online Databases", ...

  2. clip API实现遮罩

    (function () { var img; var canvas = document.getElementById("canvas"); var con = canvas.g ...

  3. 如何让div中的内容垂直居中

    虽然Div布局已经基本上取代了表格布局,但表格布局和Div布局仍然各有千秋,互有长处.比如表格布局中的垂直居中就是Div布局的一大弱项,不过好在千变万化的CSS可以灵活运用,可以制作出准垂直居中效果, ...

  4. Java_Ant 详解

    1,什么是antant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台   --因为 ...

  5. Linux基础:Grep查询&AWK查询

    Grep:搜索文件内匹配指定内容的行 常用的Grep搜索方法: 1. grep "普通搜索内容" file( 或者 cat file|grep "普通搜索内容" ...

  6. JAVA类与对象作业——动手动脑以及课后实验性问题

    一: 1.源代码 //MAO2015.10.6 //foo class Foo { int value; public Foo(int initValue) { value = initValue; ...

  7. OSVERSIONINFO

    OSVERSIONINFO结构 OSVERSIONINFO结构包含了操作系统的版本信息,包括操作系统的主版本号.副版本号.创建号.以及操作系统平台ID号和关于操作系统的其他描述信息.其定义为: typ ...

  8. css背景定位

    日期:2015-12-05 背景定位算是才弄明白: background-position:50% 50%; 图片水平和垂直居中.与 background-position:center center ...

  9. System.OutOfMemoryException: 内存不足。(转)

    主要是网站生成水印图片的时候遇到的 原文地址:http://www.cnblogs.com/longgel/archive/2010/03/24/1693776.html 今天调试asp.net 程序 ...

  10. Oracle 中的 decode

    含义解释:decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义如下:IF 条件=值1 THEN RETURN(翻译值1)ELSIF 条件=值2 THEN R ...