UItableView基本步骤(代码实现中还包含快速创建数组)
2015-03-06 16:27
211 查看
// ViewController.m // TableView基础 #import "ViewController.h" #define kHead "head" @interface ViewController ()<UITableViewDataSource , UITableViewDelegate> //<2> { NSArray *_allAry; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITableView *myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; [self.view addSubview:myTableView]; //必须实现tableview的数据源才能使用tableview <1> myTableView.dataSource = self; myTableView.delegate = self; // NSDictionary *sdDic = @{@"head": @"山东", // @"foot": @"山东欢迎您!", // @"cities" :@[@"烟台",@"济南",@"青岛",@"威海",@"淄博",@"潍坊",@"德州"] // }; _allAry = @[ @{@kHead: @"山东", @"foot": @"山东欢迎您!", @"cities" :@[@"烟台",@"济南",@"青岛",@"威海",@"淄博",@"潍坊",@"德州"] }, @{@kHead: @"北京", @"foot": @"北京欢迎您!", @"cities" :@[@"海淀区",@"石景山区",@"朝阳区",@"东城区",@"西城区",@"昌平区"] }, @{@kHead: @"江苏", @"foot": @"江苏欢迎您!", @"cities" :@[@"南京",@"徐州",@"苏州",@"常州"] }, @{@kHead: @"浙江", @"foot": @"浙江欢迎您!", @"cities" :@[@"杭州",@"宁波",@"义务"] } ]; } #pragma mark 3-1. 分几组 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return _allAry.count; } #pragma mark 3-2. 返回每个分区有几行 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[_allAry[section] objectForKey:@"cities"] count]; } #pragma mark 3-3. 每一行显示的内容 -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; cell.textLabel.text = [_allAry[indexPath.section] objectForKey:@"cities"][indexPath.row]; return cell; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [_allAry[section] objectForKey:@kHead]; } -(NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { return [_allAry[section] objectForKey:@"foot"]; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 70; } #pragma 调整每行的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
相关文章推荐
- Next数组的实现步骤与代码,以及三个简单应用(包含KMP)
- 快速排序基本思想以及代码实现
- 只需四个步骤几行代码,即可快速实现直播弹幕功能
- PowerShell创建虚拟机 (一、基本思路与实现代码)
- php 数组的创建、调用和更新实现代码
- git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0
- asp.net通过js实现Cookie创建以及清除Cookie数组的代码
- (C语言版)链表(一)——实现单向链表创建、插入、删除等简单操作(包含个人理解说明及注释,新手跟着写代码)
- Python3 -- 通过pandas实现快速创建java实体代码模板
- (C语言版)链表(一)——实现单向链表创建、插入、删除等简单操作(包含个人理解说明及注释,新手跟着写代码)
- (C语言版)链表(一)——实现单向链表创建、插入、删除等简单操作(包含个人理解说明及注释,新手跟着写代码)
- php 数组的创建、调用和更新实现代码
- asp.net通过js实现Cookie创建以及清除Cookie数组的代码
- 属性动画步骤总结——包含xml实现与java代码实现
- laravel手动创建数组分页的实现代码
- jvava 代码创建接口 通过jni实现C的调用步骤
- 常见内部排序算法 简单数组实现与分析(快速(偶原创partition函数,望众高手指正)、归并、希尔、插入、选择、冒泡)
- 排序算法集:冒泡、插入、希尔、快速(数组实现、链表实现)
- 一些vc的基本知识,创建应用实例的步骤
- 排序算法集:冒泡、插入、希尔、快速(数组实现、链表实现)