zoukankan      html  css  js  c++  java
  • IOS开发:用tableView控件展示数据

    用tableView控件展示数据,必须要实现三个方法。下面我就对这些方法进行简单的说明

    前景设置:我已经把文件名存到了一个数组里,然后把这个数组里的信息展示到tableView控件上..

    我这里的实现较为简单,大家可以去看看视频,学习些多组比较复杂点的情况

    方法一:告诉控件分为几组(在有的app栏中,看到每几行就隔开,这几行就为一组),我没分组,所以返回1

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return  1;
    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        //存了信息的数组,返回存储文件名称的数组长度
        return [[self getFileList]count];
    }

    方法二:告诉控件一组有几行,section参数表示第几组,如果只有1组,那么section参数为0;

    方法三:告诉控件每行显示什么内容

     1 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
     2 {
     3     UITableViewCell  *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
     4  //右侧的按钮样式
     5     cell.accessoryType=UITableViewCellAccessoryDetailButton;
     6    //获取存了文件信息的数组然后遍历赋值到cell文本中
     7    NSMutableArray *ss=[self getFileList];
     8 //我只有1组,那么section参数为0,此处是为了把数组里的信息循环存到cell的行中
     9     for(int i=0;i<[tableView numberOfRowsInSection:0];i++)
    10     {
    11      //   indexPath.section==0
    12     //控制每行的
    13       if( indexPath.row==i)
    14         cell.textLabel.text=[ss objectAtIndex:i];
    15     }
    16     return cell;   }
  • 相关阅读:
    (考研)散列表和hashcode和hashmap
    java基本数据类型和引用类型
    Java 中的语法糖(7/15整个周六上午总结)
    数据库第一天-数据库索引
    MonoBehaviour生命周期
    Unity基础知识
    SQLite3笔记
    cocos_js写文件
    UGUI_屏幕适配
    KMS算法
  • 原文地址:https://www.cnblogs.com/kc1995/p/13162540.html
Copyright © 2011-2022 走看看