zoukankan      html  css  js  c++  java
  • UITableView基本属性应用

    一 创建表格,并把表格添加到控制器

        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];//创建表格   指定表格的宽高为self.view.bounds就是铺满全屏    设置表格样式为分组样式UITableViewStyleGrouped  还有一个样式为UITableViewStylePlain 普通样式

        tableView.dataSource = self;//设置表格显示数据的数据源,这个必须遵循UITableViewDataSource这个协议,如果不遵循这个协议会调用不到绑定数据的方法

        [self.view addSubview:tableView]; 把表格添加到控制器

    二 设置表格绑定数据和每行cell绑定的方法

    #pragma mark - 数据源方法

    #pragma mark 一共有多少组(section == 区域组)

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView    //numberOfSenctionsInTableView方法为反回数据有多少组,并把这个组传给反回行方法,这个是自动调用的

    {

    //    NSLog(@"numberOfSections"); 

        return 3;  返回3组

    }

    #pragma mark 第section组一共有多少行

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //numberOfRowsInSection为返回多少行的方法

    {

         senction  // 这参数为上面方法传过来的第几组,这里接怍到第几组后,把相对应有几行返回过去

    }

    #pragma mark 返回每一行显示的内容(每一行显示怎样的cell)

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

       //这里接收第几组第几行的索引(indexPath.Senction,indexPath.Row),然后定义UITableViewCell 通过设置cell的相应属性并把cell返回,这样就完成了每一行显示什么数据

        UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

        cell.textLabel.text = text;

        return cell;

    }

    #pragma mark 第section组显示的头部标题

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

    {

            return @"表头";

    }

     

    #pragma mark 第section组显示的尾部标题

    - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

    {

        return @"结尾";

    }

    #pragma mark 返回表格右边的显示的索引条

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView   //该方法为显示索引条,物别注意动态数组的添加方式

    {

        NSMutableArray *titles = [NSMutableArray array];

        

        for (Province *p in _allProvinces) {

            [titles addObject:p.header];

        }

        

        return titles;

    }

  • 相关阅读:
    NetScaler ‘Counters’ Grab-Bag!
    NetScaler + Wireshark = A Perfect Combination!
    What’s That NetScaler Reset Packet?
    Give NetScaler a “Tune-Up”
    51Nod 1080 两个数的平方和(数论,经典题)
    51Nod 1289 大鱼吃小鱼(模拟,经典好题)
    1082 与7无关的数(思维题,巨坑)
    51Nod 1003 阶乘后面0的数量(数学,思维题)
    2017广东工业大学程序设计竞赛决赛 题解&源码(A,数学解方程,B,贪心博弈,C,递归,D,水,E,贪心,面试题,F,贪心,枚举,LCA,G,dp,记忆化搜索,H,思维题)
    后缀数组(一堆干货)
  • 原文地址:https://www.cnblogs.com/xgj0721/p/4340294.html
Copyright © 2011-2022 走看看