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,看名字知道,之前的一篇学习笔 ...
随机推荐
- C++,Base64编解码字符串或文件
参考链接:在C语言中使用libb64进行Base64编解码 GitHub地址:https://github.com/BuYishi/cpp_base64_demo base64_demo.cpp #i ...
- [RK3288][Android6.0] 调试笔记 --- 测试I2C设备正常传输方法【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/71515020 Platform: RockchipOS: Android 6.0Kernel ...
- YTU 2421: C语言习题 矩形法求定积分
2421: C语言习题 矩形法求定积分 时间限制: 1 Sec 内存限制: 128 MB 提交: 354 解决: 234 题目描述 写一个用矩形法求定积分的通用函数,分别求 (说明: sin,co ...
- vue中显示和隐藏导航
const router = new VueRouter({ mode: 'history', routes: [ { path: '/first', component: firstView, me ...
- 一步一步学Silverlight 2系列(10):使用用户控件
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- bzoj 1894 游戏
题目大意: $n$个装备,每个装备有两个值,可以攻击该值对应的怪兽.每个装备最多用一次 每个怪兽被打一次之后就会死,每个怪兽可以被打当且仅当前面的都死了,求最多打多少个 思路: 很明显的二分图匹配,如 ...
- C++ set和map的简单使用
C++中的STL模板库的功能可谓相当强大.今天我们来简单说一下set和map的使用方法. 1.pair 我们先来说一下pair.pair定义在头文件<utility>中,其本身相当于一个已 ...
- 877C
构造 想了好长时间... 答案是n+n/2 我们这么想,先把偶数位置炸一遍,所有坦克都在奇数位置,然后再把奇数炸一遍,坦克都到偶数去了,然后再炸一次偶数就都炸掉了... 好巧妙啊 奇偶讨论很重要 #i ...
- 09_多线程下载_获取文件长度&计算下载范围
package com.itheima.multiThreadDownload; //import java.net.MalformedURLException; import java.io.Ran ...
- c++中.c_str和.c_data
1 关于.c_str的用法: const char *c_str(); 这个数组的数据是临时的,当有一个改变这些数据的成员函数被调用后,其中的数据就会失效.因此要么现用先转换,要么把它的数据复制到用户 ...