UITableView在开发中是用的最多的控件,它包含两个代理:UITableViewDataSource,UITableViewDelegate,先熟悉下API

1.初始化

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;

2.UITableViewStyle

typedef NS_ENUM(NSInteger, UITableViewStyle) {
        UITableViewStylePlain,                  // 平铺样式
        UITableViewStyleGrouped                 // 分组样式
    };

3.style属性

@property (nonatomic, readonly) UITableViewStyle           style;

4.代理

@property (nonatomic, assign)   id <UITableViewDataSource> dataSource;
@property (nonatomic, assign)   id <UITableViewDelegate>   delegate;

5.设置Height

//未设置Height时用下面默认
    @property (nonatomic)          CGFloat                     rowHeight;
    @property (nonatomic)          CGFloat                     sectionHeaderHeight;
    @property (nonatomic)          CGFloat                     sectionFooterHeight;
    //默认为0 nil时表示无预估Height
    @property (nonatomic)          CGFloat                     estimatedRowHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic)          CGFloat                     estimatedSectionHeaderHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic)          CGFloat                     estimatedSectionFooterHeight NS_AVAILABLE_IOS(7_0);

6.背景视图 自动改变Size适应TableView的尺寸, 做为TableView的子视图放在最底部

@property(nonatomic, readwrite, retain) UIView *backgroundView NS_AVAILABLE_IOS(3_2);

7.刷新数据

- (void)reloadData; //刷新数据
- (void)reloadSectionIndexTitles NS_AVAILABLE_IOS(3_0);//分组时刷新组索引

8.节数行数

 - (NSInteger)numberOfSections; //节数量
 - (NSInteger)numberOfRowsInSection:(NSInteger)section; //节对应的行数

9.获取Rect

- (CGRect)rectForSection:(NSInteger)section;                                    // includes header, footer and all rows
- (CGRect)rectForHeaderInSection:(NSInteger)section;
- (CGRect)rectForFooterInSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;

10.Info

//    //获取point点处的NSIndexPath,若点不在任何table中的任意行则返回nil
//    - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
//    //返回制定UITableViewCell对应的NSIndexPath,不可见返回nil
//    - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;
//    //返回矩形包含的NSIndexPath
//    - (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
//     //获取indexPath处的UITableViewCell,若cell不可见或indexPath超出边界返回nil
//    - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
//    //返回可见的UITableViewCell
//    - (NSArray *)visibleCells;
//    //返回可见行的NSIndexPath数组
//    - (NSArray *)indexPathsForVisibleRows;
//    //获取Section对应的headerViewForSection、footerViewForSection
//    - (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
//    - (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

11.滚动

    //滚动到indexPath处
    - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
    //滚动到选择的行处
    - (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

12.

//标记了一个tableView的动画块。分别代表动画的开始开始和结束。两者成对出现,可以嵌套使用。一般,在添加,删除,选择 tableView中使用,并实现动效果。在动画块内,不建议使用reloadData方法,如果使用,会影响动画
    - (void)beginUpdates;
    - (void)endUpdates;

13.对节、行的增删改

 - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
    - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
    - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
    - (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_AVAILABLE_IOS(5_0);

    - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
    - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
    - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
    - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_AVAILABLE_IOS(5_0);

14.修改

   //可选中 默认YES
    @property (nonatomic) BOOL allowsSelection NS_AVAILABLE_IOS(3_0);
    //编辑的时候是否可选中  默认NO
    @property (nonatomic) BOOL allowsSelectionDuringEditing;
    //可多选 默认NO
    @property (nonatomic) BOOL allowsMultipleSelection NS_AVAILABLE_IOS(5_0);
    //多选时是否可编辑 默认NO
    @property (nonatomic) BOOL allowsMultipleSelectionDuringEditing NS_AVAILABLE_IOS(5_0);

15.选择

 //选中行的NSIndexPath
    - (NSIndexPath *)indexPathForSelectedRow;
    //选中的多行的NSIndexPaths
    - (NSArray *)indexPathsForSelectedRows;
    //选中indexPath对应的行 滚动到行的位置
    - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
    //取消选择
    - (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

16.

//当我们tableView中section有很多,数据量比较大的时候我们可以引入indexList,来方便完成section的定位,例如系统的通讯录程序。我们可以通过设置tableView的sectionIndexMinimumDisplayRowCount属性来指定当tableView中多少行的时候开始显示IndexList,默认NSIntegerMax,即默认不显示indexList
    @property (nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;

17.

//节索引的文本颜色
    @property (nonatomic, retain) UIColor *sectionIndexColor
    //节索引的背景色
    @property (nonatomic, retain) UIColor *sectionIndexBackgroundColor
    //点击时节索引背景色
    @property (nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor
    //单元格分割线的样式
    @property (nonatomic) UITableViewCellSeparatorStyle separatorStyle;
    //设置单元格分割线的颜色
    @property (nonatomic, retain) UIColor              *separatorColor
    //单元格的毛玻璃效果
    @property (nonatomic, copy) UIVisualEffect               *separatorEffect
    //UITableView的HeaderView
    @property (nonatomic, retain) UIView *tableHeaderView;
    //UITableView的FooterView
    @property (nonatomic, retain) UIView *tableFooterView;

18.

//获取重用队列中的单元格
    - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;
    //ios6之后出现 需要与registerClass、registerNib配合使用
    - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
    //获取HeaderFooterView 需要与registerClass、registerNib配合使用
    - (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
    - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
    - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

    - (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
    - (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier

UIKit 框架之UITableView一的更多相关文章

  1. UIkit框架之UItableview

    1.继承链:UIScrrollView:UIview:UIresponder:NSObject 2.创建实例的时候首先需要确定table的类型 3.一个tableview对象必须要有一个数据源和一个委 ...

  2. UIKit 框架之UITableView二

    // // ViewController.m // UITableView // // Created by City--Online on 15/5/21. // Copyright (c) 201 ...

  3. iOS学习32之UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  4. iOS开发UIKit框架-可视化编程-XIB

    1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...

  5. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  6. Swift - 重写UIKit框架类的init初始化方法(以UITabBarController为例)

    原来写了篇文章讲UITabBarController的用法,当时是从UIViewController跳转到UITabBarController页面,代码如下: 1 self.presentViewCo ...

  7. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  8. 基础框架Fundation和UIkit框架的定义和使用

    Foundation 框架为所有应用程序提供基本的系统服务 您的应用程序以及 UIKit 和其他框架,都建立在 Foundation 框架的基础结构之上.Foundation 框架提供许多基本的对象类 ...

  9. iOS开发概述UIkit动力学,讲述UIKit的Dynamic特性,UIkit动力学是UIkit框架中模拟真实世界的一些特性。

    转发:http://my.oschina.net/u/1378445/blog/335014 iOS UIKit动力学 Dynamics UIAttachmentBehavior 实现iMessage ...

随机推荐

  1. 截图-----Selenium快速入门(十二)

    在自动化测试过程中,截图是常见的操作,因为有时候单靠程序无法判断是否已得到期望的结果,所以需要截图判断.又或者截图是作为判断的存证.Selenium的截图操作也是非常简单,而且自带了一个文件操作类Fi ...

  2. jquery批量控制表单元素

    网上查了很久,避免下次再遇到相同的问题,记录一下: $("form input").prop("readonly", true); $("form i ...

  3. DevExpress WinForms Controls 学习系列1

    一个偶然的机会,接触到DevExpress.项目是WinForm的,应用了DevExpress.为了使项目具备维护开发的生命力,我觉得有必要系统的学习一下DevExpress,今天是学习笔记的第一篇. ...

  4. 红帽子系统链接加vm15秘钥一份

    vm15秘钥:YZ718-4REEQ-08DHQ-JNYQC-ZQRD0 红帽子系统下载链接:http://www.ddooo.com/softdown/60964.htm

  5. iOS - 安全

    1. CheckList http://www.jianshu.com/p/d3cc2d5c177d a 数据安全.分为数据传输安全和数据存储安全 数据存储安全为保存在App中的数据安全.不允许明文存 ...

  6. VSCode保存插件配置并使用 gist 管理代码片段

    setting sync 保存配置 由于公司和家里都使用 VSCode 作为主要编辑器,同步配置是最紧要的.VSCode 提供了setting sync插件,很方便我们同步插件配置.引用网上教程: 在 ...

  7. iOS-UIScrollView内容复用【实现两个试图的复用】

    前言 这里说的内容复用,是指添加到 ScrollView 里面的试图是同一个模型:比如,我需要在 ScrollView 上添加100个 xkView(其他封装好的VC.UIView),每次滑动 Scr ...

  8. template.js插件和ajax一起使用的例子

    template.js 一款 JavaScript 模板引擎,简单,好用.提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同的效果. https:/ ...

  9. easyUI slider滑块,在加载出来后,easyUI slider滑块禁用方法

    easyUI slider滑块禁用 如下图easyUI slider滑块,在加载出来后,需要禁止拉动 easyUI slider滑块禁用方法 //禁用$(s1).slider({ disabled:t ...

  10. php 常见图片处理函数封装

    <?php /** * 常见图像处理函数的封装 */ class Image{ private $info=[]; private $width;//原始图片宽度 private $height ...