首页 技术 正文
技术 2022年11月14日
0 收藏 903 点赞 2,936 浏览 3946 个字

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…

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901