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,看名字知道,之前的一篇学习笔 ...
随机推荐
- 今日头条上看到的js面试题和答案
用js判断字符中每个字符出现的次数, 答案是var info = arr.split('').reduce((a,b)=>(console.log(a,b),a[b]++ || (a[b]=1) ...
- mysql优化---in型子查询,exists子查询,from 型子查询
in型子查询引出的陷阱:(扫更少的行,不要临时表,不要文件排序就快) 题: 在ecshop商城表中,查询6号栏目的商品, (注,6号是一个大栏目) 最直观的: mysql); 误区: 给我们的感觉是, ...
- js 中call,apply,bind的区别
call.apply.bind方法的共同点与区别: apply.call.bind 三者都是用来改变函数的this对象的指向: apply.call.bind 三者都可以利用后续参数传参: bind ...
- 织梦dedecms页面中增加二维码功能的实现方法
本文介绍了在dedecms中增加二维码功能的实现方法,有时需要在dedecms页面增加二维码,方便手机用户访问,有需要的朋友参考下. 本节内容: dedecms中增加二维码功能 1.打开/incl ...
- node安装与升级
node安装与升级 1.安装 sudo apt-get install nodejs sudo apt-get install npm 2.升级 如果node不是最新的,node有一个模块叫n,是专门 ...
- 收集几个Android CalendarView非常用属性
android:dateTextAppearance 设置日历View在日历表格中的字体皮肤;android:firstDayOfWeek 指定日历第一个星期的第一天,在日历中横向所在位置,从右边向左 ...
- 构建Docker平台【第一篇】环境准备
主机信息 操作系统版本 CentOS-7-x86_64-Everything-1511 主机A 192.168.6.128 主节点 主机B 192.168.6.129 主节点 主机C 192.16 ...
- 多线程-threading模块2
从上面例子中发现线程的创建是颇为麻烦的,每创建一个线程都需要创建一个 t(t1.t2....),如果创建的线程较多时这样极其不方便.下面对通过例子进行改进: #coding:utf-8 impor ...
- LightOJ 1140 How Many Zeroes? (数位DP)
题意:统计在给定区间内0的数量. 析:数位DP,dp[i][j] 表示前 i 位 有 j 个0,注意前导0. 代码如下: #pragma comment(linker, "/STACK:10 ...
- hdoj3664【DP】
题意: 有一种值E=the number of elements where ai > i.比如1 3 2 4,只有3位置是满足的,E=1.然后他会给你一个数组和一个k,问有多少个序列的E=k. ...