头文件

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

#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. DOM操作一

    1.通过ID选取元素 var section = document.getElementById("section1"); 2.通过ID查找多个元素 function getEle ...

  2. (linux)wake_lock机制

      Android的休眠唤醒主要基于wake_lock机制,只要系统中存在任一有效的wake_lock,系统就不能进入深度休眠,但可以进行设备的浅度休眠操作.wake_lock一般在关闭lcd.tp但 ...

  3. ref 与 $refs 如何关联

    先问大家一个简单的问题: 还有人记得 jquery 里面的 data 方法是如何让 DOM 节点绑定对应的数据对象的吗 有时候我们做节点关联设计的思路其实有一点类似,但是在 vue 里面多了很多概念, ...

  4. POJ3680 Intervals —— 区间k覆盖问题(最小费用流)

    题目链接:https://vjudge.net/problem/POJ-3680 Intervals Time Limit: 5000MS   Memory Limit: 65536K Total S ...

  5. html5--6-6 CSS选择器3

    html5--6-6 CSS选择器3 实例 学习要点 掌握常用的CSS选择器 了解不太常用的CSS选择器 什么是选择器 当我们定义一条样式时候,这条样式会作用于网页当中的某些元素,所谓选择器就是样式作 ...

  6. maven实战(6)-- pom.xml的编写

    pom.xml中可以编写的东西确实挺多的,经常看到别人写的pom文件中出现了一些没见过plugin或properties等等,不知有何作用,其实很简单,只要参看maven的官方文档即可:http:// ...

  7. Opencv实现简易播放器

    实现了在MFC中显示图片,再要显示一个视频就是轻而易举的事了,本篇介绍使用Opencv制作一个简易的播放器,实现打开文件.暂停.继续播放.再次播放和总\当前帧数显示功能. 首先还是先看一下界面效果: ...

  8. I.MX6 u-boot 2009 lvds hdmi lcd 补丁

    /************************************************************************* * I.MX6 u-boot 2009 lvds ...

  9. 纯CSS画WP8界面

    我的手机是诺基亚920,13年4月份买的.工作之余,就想用css做一下WP8的界面效果,如上图所示.不做不知道,一做还挺难的.尤其是画那个QQ 的企鹅图标,太难画了.怎么画都不像. <!doct ...

  10. [Selenium] 操作浏览器前进后退

    driver.get("http://1.com"); driver.navigate().to("http://2.com"); driver.navigat ...