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属性和方法的更多相关文章

  1. [OC][转]UITableView属性及方法大全

    Tip: UITableView属性及方法大全  (摘录地址) p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 1 ...

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

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

  3. UIKit的外观属性及方法汇总

    本文授权转载,作者:楚天舒(简书) 开发中经常会碰到要设置UI的某个生僻的外观属性,虽然在头文件中都能查到,但一是每个控件的头文件比较分散繁杂,二是每个头文件里有太多不用到的方法和属性,所以这里将UI ...

  4. iOS开发UITableView基本使用方法总结1

    UITableView基本使用方法 1.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDataSource 2.然后 ...

  5. UITableView类用法大全:UITableView属性

    [storyboard创建tableView步骤] 1.设置根视图 2.选中视图,设置导航栏editor/embed in/navigationcontroller 3.cell设置Identifie ...

  6. iOS开发UITableView基本使用方法总结

    本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...

  7. iOS开发UITableView基本使用方法总结 分类: ios技术 2015-04-03 17:51 68人阅读 评论(0) 收藏

    本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...

  8. iOS中UIKit的外观属性及方法汇总

    这里将UIKit的外观属性及方法从头文件中抽取出来,以便查找及熟悉.(更新到iOS 8.0,从A-Z排序) UIActivityIndicatorView @property (readwrite,  ...

  9. UITableView 基本使用方法总结

    1..首先,Controller需要实现两个  delegate ,分别是  UITableViewDelegate 和  UITableViewDataSource2.然后 UITableView对 ...

随机推荐

  1. 开始3D编程前需注意的十件事

    http://www.csdn.net/article/2013-06-21/2815949-3d-programming 原文作者Vasily Tserekh是名3D编程爱好者,他发表了一篇博文&l ...

  2. android开发

    从某种意义上讲,垃圾收集机制把程序员从“内存管理噩梦”中解放出来,而 Android 的进程生命周期管理机制把用户从“任务管理噩梦”中解放出来.我见过一些 Nokia S60 用户和 Windows ...

  3. Qt创建和使用动态链接库

    一.创建共享库 1.新其他建项目,选择C++库 2.选择共享库,并取项目名称,单击下一步.这里取名位mylib 3.按默认配置单击下一步至模块选项,选择所需支持的模块.这里勾选Qtcore和QtGui ...

  4. java常量设置的方式

    我们在写java程序的时候,常常有常量设置,如: public interface Const { //性别的常量 public interface Sex{ public final int 男=1 ...

  5. Ajax--json(Ajax调用返回json封装代码、格式及注意事项)

    Ajax调用json封装代码<dbda.php>: //Ajax调用返回JSON public function JsonQuery($sql,$type=1,$db="mydb ...

  6. 第24讲 UI_布局 之帧布局 表格布局 绝对布局

    第24讲 UI_布局 之帧布局 表格布局 绝对布局 3. FrameLayout(帧布局) 帧布局是从屏幕的左上角(0,0)坐标开始布局,多个组件层叠排序,后一个组件总会将前一个组件所覆盖,除非最后一 ...

  7. 有关JAVA基础学习中的集合讨论

        很高兴能在这里认识大家,我也是刚刚接触后端开发的学习者,相信很多朋友在学习中都会遇到很多头疼的问题,希望我们都能够把问题分享出来,把自己的学习思路整理出来,我们一起探讨一起成长.    今天我 ...

  8. Android-67-Tomcat启动出错:Server Tomcat v7.0 Server at localhost failed to start.

     错误:Server Tomcat v7.0 Server at localhost failed to start.如图: 唉! ! !!图片上传不上去,悲哀啊!..仅仅能先写着错误提示语吧~~ ...

  9. POJ 2392 Space Elevator 背包题解

    多重背包.本题不须要二分优化.相对简单点.由于反复数十分小,小于10. 而添加一个限制每种材料的高度做法.假设使用逆向填表,那么仅仅须要从这个高度往小递归填表就能够了. 还有就是注意要排序,以限制高度 ...

  10. spring 通过工厂方法配置Bean

    概要: 通过调用静态工厂方法创建Bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中.当client须要对象时,仅仅须要简单地调用静态方法,而不用关心创建对象地细节. 要声明通过静 ...