UITableView属性和方法
1、初始化一个UITableView
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
struct CGRect {
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;
typedef enum {
UITableViewStylePlain, //平铺样式
UITableViewStyleGrouped //分组样式
} UITableViewStyle;
2、配置一个TableView
1)返回这个TableView的样式(只读属性)
@property(nonatomic, readonly) UITableViewStyle style
2)返回指定section内的Cell的行数
- (NSInteger)numberOfRowsInSection:(NSInteger)section
当TableView在UITableViewStylePlain下section应该为0
3)返回TableView的section数量
- (NSInteger)numberOfSections
4)设置TableView中所有cell的高度
@property(nonatomic) CGFloat rowHeight
Apple建议我们使用代理方法tableView:heightForRowAtIndexPath:代替rowHeight方法使TableView的性能更高
5)设置TableView的分隔线的样式
@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle
typedef enum : NSInteger {
UITableViewCellSeparatorStyleNone, //无分隔线
UITableViewCellSeparatorStyleSingleLine, //单分割线
UITableViewCellSeparatorStyleSingleLineEtched //被侵蚀的但分隔线
} UITableViewCellSeparatorStyle;
6)设置TableView的分隔线颜色
@property(nonatomic, retain) UIColor *separatorColor
7)设置TableView的背景视图
@property(nonatomic, readwrite, retain) UIView *backgroundView
8)设置TableView的分隔线偏移量
@property (nonatomic) UIEdgeInsets separatorInset
//Available in iOS 7.0 and later.
Apple的例子
tableView.separatorInset = UIEdgeInsetsMake(, , , );
//上、左、下、右
3、创建TableView的Cell
1)注册一个包含指定标示符TableView的Cell的nib对象
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier //两个参数不能是nil
//Available in iOS 5.0 and later.
2)注册一个类用来创建新的Cell
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier
//Available in iOS 6.0 and later.
3)使用指定的标示符返回可重用的Cell
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
//Available in iOS 6.0 and later.
Apple重要提示:使用这个方法之前必须是使用了registerNib:forCellReuseIdentifier: 或者registerClass:forCellReuseIdentifier:方法注册了Cell
4)使用指定的标示符返回可重用的Cell
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier
4、访问表头和表尾的视图
1)注册一个包含表头或表尾的指定标示符表视图的nib对象
- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier
//Available in iOS 6.0 and later.
2)注册一个类,用来创建新的包含表头或表尾的表视图
- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier
//Available in iOS 6.0 and later.
3)返回一个指定标识符的可重用的附带表头表尾的视图
- (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier
//Available in iOS 6.0 and later.
4)设置或返回该表格的表头视图
@property(nonatomic, retain) UIView *tableHeaderView
5)设置或返回该表格的表尾视图
@property(nonatomic, retain) UIView *tableFooterView
6)设置或返回该表格的表头高度
@property(nonatomic) CGFloat sectionHeaderHeight
7)设置或返回该表格的表尾高度
@property(nonatomic) CGFloat sectionFooterHeight
8)返回指定section的表头视图
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
//Available in iOS 6.0 and later.
9)返回指定section的表尾视图
- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section
//Available in iOS 6.0 and later.
5、访问Cell和Section
1)返回指定indexPath的Cell
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
2)返回指定Cell的IndexPath
- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell
3)返回指定点的IndexPath
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
4)返回指定区域内的IndexPath组成的数组
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect
5)返回可见的UITableViewCell组成的数组
- (NSArray *)visibleCells
6)返回可见表格行的IndexPath组成的数组
- (NSArray *)indexPathsForVisibleRows
6、估算元素的高度
1)设置表格行的估算高度以改善性能
@property (nonatomic) CGFloat estimatedRowHeight
//The default value is 0, which means there is no estimate.
//Available in iOS 7.0 and later.
2)设置Section头的估算高度以改善性能
@property(nonatomic) CGFloat estimatedSectionHeaderHeight
//The default value is 0, which means there is no estimate.
//Available in iOS 7.0 and later.
3)设置Section尾的古都按高度以改善性能
@property(nonatomic) CGFloat estimatedSectionFooterHeight
//The default value is 0, which means there is no estimate.
//Available in iOS 7.0 and later.
7、滚动TableView
1)滚动到指定的位置
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
typedef enum {
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,
UITableViewScrollPositionMiddle,
UITableViewScrollPositionBottom
} UITableViewScrollPosition;
To be Continue...
UITableView属性和方法的更多相关文章
- [OC][转]UITableView属性及方法大全
Tip: UITableView属性及方法大全 (摘录地址) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 1 ...
- UITableView常用属性和方法 - 永不退缩的小白菜
UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00 博客园精华区原文 http://www.cnblogs.com/zhaofucheng11 ...
- UIKit的外观属性及方法汇总
本文授权转载,作者:楚天舒(简书) 开发中经常会碰到要设置UI的某个生僻的外观属性,虽然在头文件中都能查到,但一是每个控件的头文件比较分散繁杂,二是每个头文件里有太多不用到的方法和属性,所以这里将UI ...
- iOS开发UITableView基本使用方法总结1
UITableView基本使用方法 1.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDataSource 2.然后 ...
- UITableView类用法大全:UITableView属性
[storyboard创建tableView步骤] 1.设置根视图 2.选中视图,设置导航栏editor/embed in/navigationcontroller 3.cell设置Identifie ...
- iOS开发UITableView基本使用方法总结
本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...
- iOS开发UITableView基本使用方法总结 分类: ios技术 2015-04-03 17:51 68人阅读 评论(0) 收藏
本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...
- iOS中UIKit的外观属性及方法汇总
这里将UIKit的外观属性及方法从头文件中抽取出来,以便查找及熟悉.(更新到iOS 8.0,从A-Z排序) UIActivityIndicatorView @property (readwrite, ...
- UITableView 基本使用方法总结
1..首先,Controller需要实现两个 delegate ,分别是 UITableViewDelegate 和 UITableViewDataSource2.然后 UITableView对 ...
随机推荐
- 在Visual Studio 2013中编译libssh2项目
一. 下载需要的外部包,并解压,下面给出的链接如果无法访问,就google搜索下载一下: •下载openssl •下载zlib 二.修改libssh2项目配置: 1.C/C++->Gene ...
- Android + eclipse +ADT安装完全教程
最近几天没事做,网上看来看去突然就想弄个android来学学... 首先,是要下载android SDK,在http://developer.android.com/sdk/index.html这个 ...
- OCP-1Z0-051-题目解析-第28题
28. Which two statements are true regarding constraints? (Choose two.) A. A foreign key cannot cont ...
- Android ActionBar详解(一):ActionBar概述及其创建
在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个重要的内容,Action Bar主要是用于代替传统的标题栏,对于Android平板设备来说屏幕更大它的标题使 ...
- HTML 5 视频使用
视频格式 当前,video 元素支持三种视频格式: 格式 IE Firefox Opera Chrome Safari Ogg No 3.5+ 10.5+ 5.0+ No MPEG 4 9.0+ No ...
- UVA 1558 - Number Game(博弈dp)
UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp ...
- Builder模式 初体验
看来Java构造器模式,决定动手体验下.构造器模式是什么?干什么用的?推荐大家看下ITEYE的一篇文章 http://www.iteye.com/topic/71175 了解构 ...
- jquery压缩图片插件
imageCompress 只有图片压缩功能,比较简单jquery.imageCompress.js 使用说明: el:为上传框 quality:压缩图片质量,单位为% onloadStart:读取图 ...
- 原生 javascript 学习之 js变量
1.变量的命名 方法的命名(驼峰命名法) 全部小写 : 单词与单词之间全部下划线 (my_namespace) 大小写混合 : 第一个单词首字母小写其他单词首字母大写. 规则 首字符 英文字母或下划线 ...
- UIApplication的作用
1.设置app图标右上角的数字2.设置状态栏的属性(样式.是否要显示)3.打开某个链接\发短信\打电话4.keyWindow : 访问程序的主窗口(一个程序只能有一个主窗口)5.windows : 访 ...