iOS UI10_带分区的省市区
//
// MainViewController.m
// UI10_带分区的省市区
//
// Created by dllo on 15/8/11.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)NSMutableArray *proArr;
@property(nonatomic,retain)UITableView *tableView;
@end
@implementation MainViewController
-(void)dealloc
{
[_proArr release];
[super dealloc];
}
#pragma mark 假设在初始化方法里使用self.view,此时还没有创建self.view系统会自己主动调用loadview,创建一个self.view,从而改变VC的运行流程,所以我们仅仅在初始化方法里初始化容器等数据部分,而不创建视图
//初始化方法
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self createData];
}return self;
}
-(void)createData
{
//文件的路径
NSString *path=@"/Users/dllo/Desktop/上课内容 /UI10_带分区的省市区/UI10_带分区的省市区/area.txt";
NSString *str =[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *strArr=[str componentsSeparatedByString:@"\n"];
self.proArr=[NSMutableArray array];
//省市区数组
for(NSString *temp in strArr){
if (![temp hasPrefix:@" "]) {
NSMutableDictionary *proDic=[NSMutableDictionary dictionary];
[proDic setObject:temp forKey:@"proName"];
NSMutableArray *cityArr=[NSMutableArray array];
[proDic setObject:cityArr forKey:@"cityArr"];
[self.proArr addObject:proDic];
}else if ([temp hasPrefix:@" "] && ![temp hasPrefix:@" "])
{
NSMutableDictionary *cityDic=[NSMutableDictionary dictionary];
[cityDic setValue:temp forKey:@"cityName"];
NSMutableArray *zoneArr=[NSMutableArray array];
[cityDic setValue:zoneArr forKey:@"zoneArr"];
NSMutableDictionary *proDic=[self.proArr lastObject];
NSMutableArray *cityArr=proDic[@"cityArr"];
[cityArr addObject:cityDic];
}else
{
NSMutableDictionary *proDic=[self.proArr lastObject];
NSMutableArray *cityArr=proDic[@"cityArr"];
NSMutableDictionary *cityDic=[cityArr lastObject];
NSMutableArray *zoneArr=cityDic[@"zoneArr"];
[zoneArr addObject:temp];
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor cyanColor];
self.navigationController.navigationBar.translucent=NO;
self.navigationItem.title=@"省";
self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -64) style:UITableViewStylePlain];
self.tableView.dataSource=self;
self.tableView.delegate=self;
[self.view addSubview:self.tableView];
[self.tableView release];
}
//
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSMutableArray *cityArr =self.proArr[section][@"cityArr"];
return cityArr.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.proArr.count;
}
//很多其它
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *newView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)] autorelease];
newView.backgroundColor=[UIColor yellowColor];
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
[newView addSubview:label];
[label release];
label.text=self.proArr[section][@"proName"];
UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(300, 0, 40, 20);
[button setTitle:@"很多其它" forState:UIControlStateNormal];
[newView addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
return newView;
}
-(void)click:(UIButton *)button
{
NSLog(@"da");
}
//创建cell,显示数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuse=@"reuse";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
}
//省字典
NSMutableDictionary *proDic=self.proArr[indexPath.section];
NSMutableArray *cityArr=proDic[@"cityArr"];
cell.textLabel.text=cityArr[indexPath.row][@"cityName"];
return cell;
}
//调到第二个页面
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *secondVC=[[SecondViewController alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
}
//分区头标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return self.proArr[section][@"proName"];
}
- (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
// UI10_带分区的省市区
//
// Created by dllo on 15/8/11.
// 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 cyanColor];
}
- (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 UI10_带分区的省市区的更多相关文章
- ios自带的返回按键,点击不刷新页面
1.因为是微信端页面,需要获取用户基本信息和设置微信分享朋友圈等功能,ios自带的返回键没有这个功能,导致config配置不成功,该隐藏的按钮没有隐藏. 解决方法,在子页面添加一下js代码即可.链接的 ...
- IOS自带输入法中文不触发KEYUP事件导致vue双向绑定错误问题
先上图: 可以看到输入框中的内容和弹出框的内容不一致, <input class="am-fr labRight" id="txcode" type=&q ...
- Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解
不多说,直接上干货! Ubuntukylin-14.04-desktop(带分区)安装步骤详解 Ubuntu14.04安装之后的一些配置 Ubuntukylin-14.04-desktop( 不带分区 ...
- Ubuntukylin-14.04-desktop(带分区)安装步骤详解
不多说,直接上干货! 成功! Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntu1 ...
- [原] corePlot 类库与iOS自带类库使用方法对比(很多开源代码都有这个特点)
——人类最倚重的是自己的“以往经验”.—— 我们直接看一下在corePlot 类库和iOS自带类中为一个控件设置文本显示格式的实现. * corePlot 类库中,为一个对象设置标题显示格式 , ...
- iOS自带TTS技术的实现即语音播报
文本转语音技术, 也叫TTS, 是Text To Speech的缩写. iOS如果想做有声书等功能的时候, 会用到这门技术. 一,使用iOS自带TTS需要注意的几点: iOS7之后才有该功能 需要 A ...
- 【ODPS】阿里云ODPS中带分区的表操作
1.创建分区表: 分区表有自己的分区列,而分区表则没有. public static void createTableWithPartition(Odps odps, String createTab ...
- iOS自带地图纠偏问题
…………纠偏 篇………….. 1. 涉及接口:<CoreLocation/CoreLocation.h> 2. 核心代码解读: if ([CLLocationManager locatio ...
- vue ios自带拼音全键输入法模糊查询兼容性问题
ios的自带拼音全键会在输入框中输入拼音,直接在输入框用@keyup="autoInput()"的话,在监听输入事件的时候安卓显示正常, ios就会出现输入显示数据不灵敏 解决办法 ...
随机推荐
- ubuntu16.04安装配置mysql数据库,分割视频为帧图像
参考http://wiki.ubuntu.org.cn/MySQL%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97 版本为5.7 一.安装 安装命令sudo apt-get i ...
- 0x41 并查集
太菜了才做到并查集啊啊啊啊啊啊啊啊啊啊啊 还是很有收获的说 水 bzoj4195: [Noi2015]程序自动分析 好题 poj1456 感受到并查集传递性的美妙啊!对于一个商品,去找他过期前那天的集 ...
- java中字符串编码转换
Java 正确的做字符串编码转换 字符串的内部表示? 字符串在java中统一用unicode表示( 即utf-16 LE) , 对于 String s = "你好哦!"; 如果源码 ...
- Ubuntu14.04下Mongodb的Java API编程实例(手动项目或者maven项目)
不多说,直接上干货! 若大家,不会安装的话,则请移步,随便挑选一种. Ubuntu14.04下Mongodb(在线安装方式|apt-get)安装部署步骤(图文详解)(博主推荐) Ubuntu14.04 ...
- Android Studio 一些注意事项(自用,不定期更新)
1,Android Studio 版本的选择 写这篇的时候,官方版本已经到了 v3.2.0,而我习惯使用的版本是 v2.3.1,因为这个版本有自带sdk的安装版,比较方便, 同时,v2.3.1 新建项 ...
- firstChild与firstElementChild
相同点: 都是获取父元素下的第一个节点对象 不同点: firstChild: IE6.7.8 第一个元素节点; 非IE6.7.8:返回第一个元素节点或文本节点 firstElementChild: I ...
- 401 - Unauthorized: Access is denied due to invalid credentials.
solution:change application pool from ApplicationPoolIdentity to NetworkService.
- Codeforces Round #283 (Div. 2) A
解题思路:给出一个递增数列,a1,a2,a3,-----,an.问任意去掉a2到a3之间任意一个数之后, 因为注意到该数列是单调递增的,所以可以先求出原数列相邻两项的差值的最大值max, 得到新的一个 ...
- Block formatting context & Inline formatting context(BFC&IFC)的区别(转载)
何为BFC与IFC bfc与ifc是针对页面正常流的两种环境,块级元素处于bfc环境中,行内元素处于ifc环境中. 元素是块级元素or行内元素由其display属性决定: block, table, ...
- NTP同步底层实现
RFC http://www.ietf.org/rfc/rfc5905.txt https://www.eecis.udel.edu/~mills/ntp/html/select.html https ...