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

转载于:https://www.cnblogs.com/zhaofucheng1129/p/3754265.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值