iOS UI08_UITableView
(http://img.blog.csdn.net/20150808103801391)
//
// MainViewController.m
// UI08_UITableView
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@end
@implementation MainViewController
-(void)dealloc
{
[_arr release];
[super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor yellowColor];
self.navigationController.navigationBar.translucent=NO;
self.navigationItem.title=@"表视图";
UITableView *tableView =[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];
tableView.backgroundColor=[UIColor cyanColor];
[self.view addSubview:tableView];
[tableView release];
//设置行高
tableView.rowHeight=100;
//两套代理的方法
tableView.dataSource=self;
//第二套协议代理人
tableView.delegate=self;
}
#pragma mark tableView第一个必须实现的协议方法,指定分区内有多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//让数组里的元素个数和行数保持同样
// return self.arr.count;
//奇数分区有五行,偶数分区有十行
//先运行设置分区的方法,后运行每一个分区有多少行
if (section % 2 == 1) {
return 5;
}else{
return 10;
}
}
#pragma mark 第二个协议方法,主要用来显示数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//创建相应个数的cell
//static 特点 1.仅仅初始化一次2.假设没有初始值,默认是0 3.直到程序结束,才会消失
//当cell显示结束之后,会把cell统一放到重用池中,等须要cell显示了,先从重用池中找,看有没有闲置cell,假设有就用闲置的cell,假设没有在创建
//cell的重用目的是为了节约成本,用有限的cell把全部数据都显示出来
//给重用池设置一个重用的标志,依据这个标志找到相应的重用池
//tableview通过重用标志在重用池中寻找cell,假设有闲置的cell,cell会保存一个有效地cell对象地址,假设没有,cell里则为nil,空
static NSString *reuse=@"reuse";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse];
//假设没有cell,则进行cell的创建
if (!cell) {
cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
}
//对cell进行赋值
//cell中有三个默认控件
cell.textLabel.text=self.arr[indexPath.row];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%ld",indexPath.section];
cell.imageView.image=[UIImage imageNamed:@"scratch.png"];
//indexPath保存的行数,从0開始,
NSLog(@"%ld",indexPath.row);
return cell;
}
#pragma mark tableview里有多少个section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 10;
}
//分区的头标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"水浒";
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.arr;
}
//第二套协议
#pragma mark table的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"section:%ld,row:%ld",indexPath.section,indexPath.row);
//打印点击的人名是什么
NSLog(@"%@",self.arr[indexPath.row]);
//点击之后跳到下一页
SecondViewController *secVC=[[SecondViewController alloc] init];
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// SecondViewController.m
// UI08_UITableView
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor orangeColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
iOS UI08_UITableView的更多相关文章
- iOS可视化动态绘制连通图
上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
- iOS总结_UI层自我复习总结
UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...
- iOS代码规范(OC和Swift)
下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- 告别被拒,如何提升iOS审核通过率(上篇)
iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...
- Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)
本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...
- Summary of Critical and Exploitable iOS Vulnerabilities in 2016
Summary of Critical and Exploitable iOS Vulnerabilities in 2016 Author:Min (Spark) Zheng, Cererdlong ...
随机推荐
- iOS开发之autoLayout constraint
前言 ios设备的尺寸越来越多,针对一款app可能要适配到多种设备.多种尺寸.所以.我们期望我们的app可以autoLayout.本文主要介绍在Xcode中使用constraint.未来会不定期对此文 ...
- android创建桌面快捷键shortcut
有非常多人也写过创建桌面快捷键的blog.可是大部分都仅仅讲了怎么用,事实上技术使用起来都非常easy.可是你使用后下次还知道吗? 根本原因还是不清楚原理.今天我就来讲讲shortcut创建过程. 过 ...
- .NET开源的背后:是无奈,还是顺应潮流?
摘要:微软.NET的开源,让很多开发者欣喜若狂.同一时候也有很多人好奇其背后的故事,过去视开源为癌症的微软为什么会突然有这一举措,是出于无奈,还是顺应潮流,而这当中的种种也许能够用文中的六个观点来说明 ...
- java 基本数据类型及自己主动类型提升
基本数据类型:8种 1.整型: byte 1个字节 8位 -128到127 short 2个字节 16位 -2^15到(2^15)-1 int 4个字节 32 ...
- 杂项:CMM
ylbtech-杂项:CMM CMM是指“能力成熟度模型”,其英文全称为Capability Maturity Model for Software,英文缩写为SW-CMM,简称CMM.它是对于软件组 ...
- T7315 yyy矩阵折叠(长)
题目背景 全场基本暴零 题目描述 输入输出格式 输入格式: 如图 输出格式: 如图 输入输出样例 输入样例#1: 2 2 1 -2 3 -4 输出样例#1: 4 输入样例#2: 2 5 1 -2 -3 ...
- hdu 3549 Flow Problem 【最大流】
其实还是不是很懂dinic----- 抄了一个模板--- http://www.cnblogs.com/naturepengchen/articles/4403408.html 先放在这里--- #i ...
- day16 闭包以及装饰器(好东西)
目录 闭包 装饰器 最基础的装饰器 完善装饰器 有返回值的 有参数的 装饰器模版 语法糖 登录装饰器 可变类型的局部变量可以修改全局变量 三层装饰器 闭包 首先要理解函数对象的概念,其实函数名就相当于 ...
- router+x
vue-router官方的路由管理器 包含的功能: ——绑定方法进行跳转 路由嵌套 写的不一样搜索的路由路径也不一样 二级路由 设置默认路由 导航守卫: 用于强制跳转或者取消的方式 ...
- 服务器上安装anaconda
1.在anaconda网站下载安装包: 清华镜像网站:https://repo.continuum.io/archive/index.html 2.下载最新版本为python3 ,Linux64位的: ...