ios学习笔记 UITableView(纯代码) (二)
头文件
---------------------------------------------
#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(纯代码) (二)的更多相关文章
- iOS学习笔记之回调(二)
写在前面 上一篇学习笔记中简单介绍了通过目标-动作对实现回调操作:创建两个对象timer和logger,将logger设置为timer的目标,timer定时调用logger的sayOuch函数.在这个 ...
- ios学习笔记 UITableView(纯代码) (一)
参考 “https://www.cnblogs.com/ai-developers/p/4557487.html” UITableViewCell 有一个代码重用 减少资源的浪费 参考 https: ...
- iOS学习笔记29-系统服务(二)通讯录
一.通讯录 iOS中的通讯录是存储在数据库中的,由于iOS的权限设计,开发人员是不允许直接访问通讯录数据库的,实现通讯录操作需要使用到AddressBook.framework框架. AddressB ...
- iOS: 学习笔记实例, 用代码控制视图创建与切换
1. 创建iOS, Single View Application.2. 修改YYViewController.m // // YYViewController.m // DynamicViewDem ...
- iOS学习笔记20-地图(二)MapKit框架
一.地图开发介绍 从iOS6.0开始地图数据不再由谷歌驱动,而是改用自家地图,当然在国内它的数据是由高德地图提供的. 在iOS中进行地图开发主要有三种方式: 利用MapKit框架进行地图开发,利用这种 ...
- iOS学习笔记13-网络(二)NSURLSession
在2013年WWDC上苹果揭开了NSURLSession的面纱,将它作为NSURLConnection的继任者.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用 ...
- iOS学习笔记(4) — UITableView的 重用机制
iOS学习笔记(4) — UITableView的 重用机制 UITableView中的cell是动态的,在使用过程中,系统会根据屏幕的高度(480)和每个cell的高度计算屏幕中需要显示的cell的 ...
- iOS学习笔记之UITableViewController&UITableView
iOS学习笔记之UITableViewController&UITableView 写在前面 上个月末到现在一直都在忙实验室的事情,与导师讨论之后,发现目前在实验室完成的工作还不足以写成毕业论 ...
- [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading
上次在<iOS学习笔记46——图片异步加载之SDWebImage>中介绍过一个开源的图片异步加载库,今天来介绍另外一个功能类似的EGOImageLoading,看名字知道,之前的一篇学习笔 ...
随机推荐
- BZOJ2327: [HNOI2011]勾股定理
BZOJ2327: [HNOI2011]勾股定理 Description 题解Here! 这是一道神题... 我一开始把题目看错了,我以为是在$n$根木棒中选两个$i,j$满足$gcd(i,j)==1 ...
- Deep Learning 33:读论文“Densely Connected Convolutional Networks”-------DenseNet 简单理解
一.读前说明 1.论文"Densely Connected Convolutional Networks"是现在为止效果最好的CNN架构,比Resnet还好,有必要学习一下它为什么 ...
- Java面试手写代码题
1.栈实现 2.Iterator实现 3.单例 4.多线和控制(暂停,恢复,停止) 5.生产者消费者
- 微信公众号菜单与应用交互session
http://www.cnblogs.com/yank/p/3476874.html http://blog.csdn.net/zmhawk/article/details/43671195 http ...
- 为了cider,尝试emacs的坑
https://github.com/clojure-emacs/cider http://clojure-doc.org/articles/tutorials/emacs.html emacs通过b ...
- POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65 ...
- RedisCluster集群搭建
搭建集群方案 安装部署任何一个应用其实都很简单,只要安装步骤一步一步来就行了.下面说一下 Redis 集群搭建规划,由于集群至少需要6个节点(3主3从模式),所以,没有这么多机器给我玩,我本地也起不了 ...
- python读取一个文件的每一行判断是否为素数,并把结果写到另一个文件中
刚刚学习python的菜鸟,这道题包括:文件的读写,python的参数调用,异常的使用,函数的使用 创建一个文本文件inti_prime.txt 执行命令:python Prime.py init_p ...
- CodeForces161D: Distance in Tree(树分治)
A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a ...
- [Selenium] 如何绕过 IE 的安全模式
自从 IE7 引入 Protected Mode 以来, IE 浏览器的安全性的确得到了一定程度的提高.其原理从本质来讲,在浏览某些需要启用保护模式的页面时,会开启一个新的浏览器会话以完成任务,而此时 ...