UITableView的操作过程

首先需要初始化table,

UITableView * table;  这个我感觉申请成全局变量好一些

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

由于要设置 table.delegate = self;        table.dataSource = self;

所以在最上面interface旁边要加上       数据源和委派<UITableViewDelegate,UITableViewDataSource>

记得将初始化好的table加入到  self.view中


然后开始进行别的函数

//在interface旁边加了 数据源和委派  之后才能用这个

//这个函数是返回组数

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}

//这个函数是返回一组内cell的个数

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

//然后才进行生成或者是在数据池里寻找cell

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

{

           static NSString * cellId = @"cellId";//首先定义一个字符串对象,用来做cell的标记,下面会用到

          //  然后在数据池里找标记为cellId的 cell,找到,就直接显示出来,没找到,就要初始化这个cell 了

          UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];

         if(!cell)  //如果没找到

       {

                    cell=[[UITableViewCell  alloc]init];//初始化生成cell

         }

       tableView.rowHeight = 200;//定义cell的高度

       NSInteger row1 = indexPath.row;//获取cell的索引

       然后再加cell上的其他东西


     最后返回cell

    return    cell;

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,311评论 1 14
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,954评论 3 38
  • 哦吼吼,又研究了几天,把FMDB这个封装好的数据库搞定了,写了个简单的例子,基于FMDB的添删改查操作,界面很一般...
    lichengjin阅读 3,630评论 0 0
  • AppDelegate.m #import "AppDelegate.h" #import "ViewContro...
    哈喽Mm阅读 2,744评论 0 0
  • UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyle...
    Windv587阅读 3,038评论 0 1