头文件

---------------------------------------------

#import <UIKit/UIKit.h>

/**

UITableViewDataSource 表视图数据源协议,用来控制表视图的显示内容

UITableViewDelegate 表视图协议 用来控制表视图的显示以及每一个cell的高度和每个分区的头尾高度等

协议的介绍   https://www.cnblogs.com/jukaiit/p/4702797.html

*/

@interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>

{

UITableView * tableView;

NSArray * array;

}

//引用UITableView

@property (strong,nonatomic)UITableView * tableView;

//存放数据的数组

@property (strong,nonatomic) NSArray * array;

@end

--------------------------------------------------------

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

//功能:让编译器自动编写一个与数据成员同名的方法声明来省去读写方法的声明。

// 详情 https://www.cnblogs.com/AnnieBabygn/p/7742628.html

@synthesize tableView;

@synthesize array;

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self MyArray];

[self MyTableView];

}

//定义的tableView

-(void) MyTableView

{

tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

tableView.dataSource = self;

tableView.delegate = self;

[self.view addSubview:tableView];

}

//添加数据

-(void) MyArray

{

NSMutableArray * MutableArr = [[NSMutableArray alloc] init];

for (int i = 0; i < 15 ; i++) {

NSString * value = [NSString stringWithFormat:@"this is  %d cell",i];

[MutableArr addObject:value];

}

array = MutableArr;

}

// 这个函数是显示tableview的 section 个数

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 1;

}

// 显示多少个 cell

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

//取决于数组的长度

return [array count];

}

// cell 的内容

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

{

//防止重复的TableView

static NSString * CellIdentifier = @"MyCell";

//减少内存  和上一篇的有一点点不一样

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)

{

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

}

//遍历数组

cell.textLabel.text = [array objectAtIndex:[indexPath row]];

return cell;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

ios学习笔记 UITableView(纯代码) (二)的更多相关文章

  1. iOS学习笔记之回调(二)

    写在前面 上一篇学习笔记中简单介绍了通过目标-动作对实现回调操作:创建两个对象timer和logger,将logger设置为timer的目标,timer定时调用logger的sayOuch函数.在这个 ...

  2. ios学习笔记 UITableView(纯代码) (一)

    参考 “https://www.cnblogs.com/ai-developers/p/4557487.html” UITableViewCell 有一个代码重用 减少资源的浪费 参考  https: ...

  3. iOS学习笔记29-系统服务(二)通讯录

    一.通讯录 iOS中的通讯录是存储在数据库中的,由于iOS的权限设计,开发人员是不允许直接访问通讯录数据库的,实现通讯录操作需要使用到AddressBook.framework框架. AddressB ...

  4. iOS: 学习笔记实例, 用代码控制视图创建与切换

    1. 创建iOS, Single View Application.2. 修改YYViewController.m // // YYViewController.m // DynamicViewDem ...

  5. iOS学习笔记20-地图(二)MapKit框架

    一.地图开发介绍 从iOS6.0开始地图数据不再由谷歌驱动,而是改用自家地图,当然在国内它的数据是由高德地图提供的. 在iOS中进行地图开发主要有三种方式: 利用MapKit框架进行地图开发,利用这种 ...

  6. iOS学习笔记13-网络(二)NSURLSession

    在2013年WWDC上苹果揭开了NSURLSession的面纱,将它作为NSURLConnection的继任者.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用 ...

  7. iOS学习笔记(4) — UITableView的 重用机制

    iOS学习笔记(4) — UITableView的 重用机制 UITableView中的cell是动态的,在使用过程中,系统会根据屏幕的高度(480)和每个cell的高度计算屏幕中需要显示的cell的 ...

  8. iOS学习笔记之UITableViewController&UITableView

    iOS学习笔记之UITableViewController&UITableView 写在前面 上个月末到现在一直都在忙实验室的事情,与导师讨论之后,发现目前在实验室完成的工作还不足以写成毕业论 ...

  9. [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading

    上次在<iOS学习笔记46——图片异步加载之SDWebImage>中介绍过一个开源的图片异步加载库,今天来介绍另外一个功能类似的EGOImageLoading,看名字知道,之前的一篇学习笔 ...

随机推荐

  1. JS简单正则得到字符串中特定的值

    这里就直接看演示样例吧.演示样例的目的是为了获取 a 字符串中的 c02806015 <script language="javascript"> var a = '礼 ...

  2. code[VS] 1297 硬币

    题目描写叙述 Description 我们知道即使是同一种面值的硬币,它们的重量也有可能不一样,由于它受到很多因素的影响,包含制造工艺和流程上的.可是不论什么一种面值的硬币的重量总是处于某个特定范围之 ...

  3. 分享一个好用的函数吧,将js中的对象转成url参数

    JavaScript&jQuery获取url参数方法 这个函数呢是自己在写基于Vue+ElementUI管理后台时用到的,,下面列出来两种使用方式: 最普通的,封装一个js函数 /** * 对 ...

  4. 利用Swoole实现PHP+websocket直播,即使通讯

    websocket Websocket只是一个网络通信协议,就像 http.ftp等都是网络通信的协议一样:相对于HTTP这种非持久的协议来说,Websocket是一个持久化网络通信的协议: WebS ...

  5. 书写优雅的shell脚本(插曲)- /proc/${pid}/status

    Linux中/proc/[pid]/status详细说明 博客分类: OS Linux多线程  [root@localhost ~]# cat /proc/self/status  Name: cat ...

  6. 网易短信接口集成 nodejs 版

    /* name:网易短信服务集成nodejs版: author:zeq time:20180607 test: // checkValidCode('157****6954','284561').th ...

  7. SQL查询速度

    查询速度 https://www.cnblogs.com/ZaraNet/p/9558272.html 影响你的查询速度的原因是什么? 网速不给力,不稳定. 服务器内存不够,或者SQL 被分配的内存不 ...

  8. Codefroces #404 Div2

    A题 分析:把多面体和面数一一对应即可 #include<iostream> #include<map> #include<cstring> #include< ...

  9. CCRect 构造函数的几个参数解释

    转自: http://blog.163.com/hzklclick_wy/blog/static/21550517520137139511839/     void CCRect::setRect(f ...

  10. 廖雪峰python3练习题二

    字符串和编码 题目: 答案: #!/usr/bin/env python3 #-*- coding:utf-8 -*- s1 = 72 s2 = 85 print('小明的成绩提高了%.1f%%个百分 ...