UITableView常用属性和方法 - 永不退缩的小白菜
UITableView常用属性和方法 - 永不退缩的小白菜
1、初始化一个UITableView
1 - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
1 struct CGRect {
2 CGPoint origin;
3 CGSize size;
4 };
5 typedef struct CGRect CGRect;
1 typedef enum {
2 UITableViewStylePlain, //平铺样式
3 UITableViewStyleGrouped //分组样式
4 } UITableViewStyle;
2、配置一个TableView
1)返回这个TableView的样式(只读属性)
1 @property(nonatomic, readonly) UITableViewStyle style
2)返回指定section内的Cell的行数
1 - (NSInteger)numberOfRowsInSection:(NSInteger)section
当TableView在UITableViewStylePlain下section应该为0
3)返回TableView的section数量
1 - (NSInteger)numberOfSections
4)设置TableView中所有cell的高度
1 @property(nonatomic) CGFloat rowHeight
Apple建议我们使用代理方法tableView:heightForRowAtIndexPath:代替rowHeight方法使TableView的性能更高
5)设置TableView的分隔线的样式
1 @property(nonatomic) UITableViewCellSeparatorStyle separatorStyle
1 typedef enum : NSInteger {
2 UITableViewCellSeparatorStyleNone, //无分隔线
3 UITableViewCellSeparatorStyleSingleLine, //单分割线
4 UITableViewCellSeparatorStyleSingleLineEtched //被侵蚀的但分隔线
5 } UITableViewCellSeparatorStyle;
6)设置TableView的分隔线颜色
1 @property(nonatomic, retain) UIColor *separatorColor
7)设置TableView的背景视图
1 @property(nonatomic, readwrite, retain) UIView *backgroundView
8)设置TableView的分隔线偏移量
1 @property (nonatomic) UIEdgeInsets separatorInset
2 //Available in iOS 7.0 and later.
Apple的例子
1 tableView.separatorInset = UIEdgeInsetsMake(0, 3, 0, 11);
2 //上、左、下、右
3、创建TableView的Cell
1)注册一个包含指定标示符TableView的Cell的nib对象
1 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier //两个参数不能是nil
2 //Available in iOS 5.0 and later.
2)注册一个类用来创建新的Cell
1 - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.
3)使用指定的标示符返回可重用的Cell
1 - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
2 //Available in iOS 6.0 and later.
Apple重要提示:使用这个方法之前必须是使用了registerNib:forCellReuseIdentifier: 或者 registerClass:forCellReuseIdentifier:方法注册了Cell
4)使用指定的标示符返回可重用的Cell
1 - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier
4、访问表头和表尾的视图
1)注册一个包含表头或表尾的指定标示符表视图的nib对象
1 - (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.
2)注册一个类,用来创建新的包含表头或表尾的表视图
1 - (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.
3)返回一个指定标识符的可重用的附带表头表尾的视图
1 - (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.
4)设置或返回该表格的表头视图
1 @property(nonatomic, retain) UIView *tableHeaderView
5)设置或返回该表格的表尾视图
1 @property(nonatomic, retain) UIView *tableFooterView
6)设置或返回该表格的表头高度
1 @property(nonatomic) CGFloat sectionHeaderHeight
7)设置或返回该表格的表尾高度
1 @property(nonatomic) CGFloat sectionFooterHeight
8)返回指定section的表头视图
1 - (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
2 //Available in iOS 6.0 and later.
9)返回指定section的表尾视图
1 - (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section
2 //Available in iOS 6.0 and later.
5、访问Cell和Section
1)返回指定indexPath的Cell
1 - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
2)返回指定Cell的IndexPath
1 - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell
3)返回指定点的IndexPath
1 - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
4)返回指定区域内的IndexPath组成的数组
1 - (NSArray *)indexPathsForRowsInRect:(CGRect)rect
5)返回可见的UITableViewCell组成的数组
1 - (NSArray *)visibleCells
6)返回可见表格行的IndexPath组成的数组
1 - (NSArray *)indexPathsForVisibleRows
6、估算元素的高度
1)设置表格行的估算高度以改善性能
1 @property (nonatomic) CGFloat estimatedRowHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.
2)设置Section头的估算高度以改善性能
1 @property(nonatomic) CGFloat estimatedSectionHeaderHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.
3)设置Section尾的古都按高度以改善性能
1 @property(nonatomic) CGFloat estimatedSectionFooterHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.
7、滚动TableView
1)滚动到指定的位置
1 - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
1 typedef enum {
2 UITableViewScrollPositionNone,
3 UITableViewScrollPositionTop,
4 UITableViewScrollPositionMiddle,
5 UITableViewScrollPositionBottom
6 } UITableViewScrollPosition;
To be Continue...
UITableView常用属性和方法 - 永不退缩的小白菜的更多相关文章
- 12-27 UITableView常用属性及方法
UITableView也有自己的代理协议,它本身继承自UIScrollView 一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法: 1.改变某一行的行 ...
- UIScrollView,UICollectionView 和UITableView的属性和方法
UIScrollView,UICollectionView 和UITableView 三者之间的关系:UIScrollView是 UICollectionView 和 UITableView 的父类. ...
- Node.js process 模块常用属性和方法
Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...
- ios基础篇(四)——UILabel的常用属性及方法
UILabel的常用属性及方法:1.text //设置和读取文本内容,默认为nil label.text = @”文本信息”; //设置内容 NSLog(@”%@”, label.text); //读 ...
- UIView的一些常用属性和方法
UIView的一些常用属性和方法 1. UIView的属性 UIView继承自UIResponder,拥有touches方法. - (instancetype)initWithFrame:(CGRec ...
- SVG DOM常用属性和方法介绍(1)
12.2 SVG DOM常用属性和方法介绍 将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析 ...
- 第190天:js---String常用属性和方法(最全)
String常用属性和方法 一.string对象构造函数 /*string对象构造函数*/ console.log('字符串即对象');//字符串即对象 //传统方式 - 背后会自动将其转换成对象 / ...
- UIView常用属性与方法/UIKit继承结构
UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...
- JavaScript中Number常用属性和方法
title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...
随机推荐
- 五个新知识:微软SHA2补丁,亚信专业工具,微软官方文档,使用过期签名(附官方推荐链接),注意使用具有UAC的CMD
五个新知识:微软SHA2补丁,亚信专业工具,微软官方文档,使用过期签名 不支持SHA2算法的计算机更新补丁:https://technet.microsoft.com/zh-CN/library/se ...
- MVC4.0中ViewBag、ViewData、TempData和ViewModel几种传值方式的区别
MVC框架实现了数据的分离,使页面看起来更加的简洁,MVC4.0中Controller和View的数据传输有上边这几种方式,今天我们来探讨下这几种方式的却别. 一:ViewBag和ViewData V ...
- Java程序员在用的大数据工具,MongoDB稳居第一!
据日前的一则大数据工具使用情况调查,我们知道了Java程序猿最喜欢用的大数据工具. 问题:他们最近一年最喜欢用什么工具或者是框架? 受访者可以选择列表中的选项或者列出自己的,本文主要关心的是大数据工具 ...
- 电脑上已经安装mysql之后安装wamp,wamp中的mysql无法启动的解决办法
Wampserver安装完成后无法启动MySQL这有可能是你之前安装过MysqL,因为wampserver内置MySQL.解决的方法就是配置环境变量. 找到我的电脑或计算机右键,打开属性,然后打开高级 ...
- CSS常用操作-导航栏
1.垂直导航栏 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- jquery1.7.2的源码分析(六)基本功能
jQuery.fn.extend({ attr: function( name, value ) { return jQuery.access( this, jQuery.attr, name, va ...
- 加上固件密码,Mac更安全
在Mac OS X中,管理员密码非常重要,在修改系统参数或安装软件时都要求输入密码,这避免了绝大部分的破坏性误操作和恶意程序(尽管Mac上恶意程序本来就少的可怜). 但是对Mac OS X比较熟悉的人 ...
- Jmeter压力测试环境准备
Jmeter性能监控 配置好测试机器上的jmeter环境:http://jmeter-plugins.org/downloads/all/ 网站下载两个东西: JMeterPlugins-Standa ...
- JS中的Math.ceil和Math.floor函数的用法
Math.ceil(x) -- 返回大于等于数字参数的最小整数(取整函数),对数字进行上舍入 Math.floor(x)--返回小于等于数字参数的最大整数,对数字进行下舍入 例如: document. ...
- myPagination5.0 分页简单实例
记得最開始做分页採用的ThreadLocal对象,后面发现有有了更简便的方法,直接使用插件,不但简单.并且高效! 採用的版本号为myPagination5.0,可以解决client多条件无刷新动态分页 ...