tableView的用法具体解释

1 tableView的类型
  1.1 UITableViewStylePlain  没有区头 不显区头     向上滑动区头不会移动到屏幕外面
’ 1.2 UITableViewStyleGrouped  有区头          表滑动,区头会移动
2 cell accessory   cell的配件
//cell配件(accessory)
// 0 none 什么也没有
// 1 DisclosureIndicator  多了一个指向右側的button
// 2 DetailButton 具体信息button
    // 3 Checkmark 对勾
// 4 DetailDisclosureButton  具体信息button + 指向右側的箭头
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;


    还能够在设置huadong




3 设置cell 选中状态
  //设置选择类型 默觉得灰底
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;

4 NSCopying 协议 作用是仅仅有实现此方法的类就能够调用copy方法
系统的某些类是默认实现NSCopying协议,诸如NSSting,NSArray,NSDictionary等;
      所以 之前的People的类的对象默认是不能调用copy方法,由于People没有实现NSCopying协议中的copyWithZone方法.
    暂时字符串的引用计数是 -1  NSString *str = @"laosun";
通过创建字符串的对象的方式 引用计数为1 能够进行拷贝 引用计数加 1 效果等同于retain   
  NSString *str1 = [NSString stringWithFormat:@"laosun"];


  4.1 浅拷贝 copy
            retain拷贝的时指针,对象仅仅有一个,结果使得对象的引用计数 + 1
   4.2 深拷贝  真正意义上的拷贝,仅仅是要产生两个对象,并且每一个对象的引用计数是1


5 //  此属性就能够取代 设置区头高度的 协议方法
_tableView.sectionHeaderHeight = 50;


6 创建tableView所必须的三个方法
    6.1  //在tableView上有几个区域
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 6.2 //每一个区域有多上行
     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 6.3  每一行的cell
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath




7 相关协议
7.1  区头须要多个控件 则能够先创建一个View,然后再view上加入控件,view和相关控件在例如以下的方法中创建
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;


   7.2  设置cell的编辑风格
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;


     风格类型
     7.2.1 UITableViewCellEditingStyleDelete      删除
7.2.2     UITableViewCellEditingStyleInsert 插入
     7.2.3 UITableViewCellEditingStyleNone        默认


    7.3 cell能否够移动 返回的时一个BOOL值
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath


    7.3.1 用来移动的三杠
     - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath


  移动逻辑: 取>删>加入


   7.4  完毕编辑


        -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;


删除和插入所做的操作写在这里 删除逻辑:删除对象 > 删除行


8  展开闭合逻辑:
通过一个bool值推断(_falg[3]),假设是yes则返回对应数组的count,否则返回0 (在和行相关的方法中),刷新对应的行的数据


9    表的编辑  增 ,删 ,移
原文地址:https://www.cnblogs.com/yutingliuyl/p/7354339.html