//
// 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_带分区的省市区的更多相关文章

  1. ios自带的返回按键,点击不刷新页面

    1.因为是微信端页面,需要获取用户基本信息和设置微信分享朋友圈等功能,ios自带的返回键没有这个功能,导致config配置不成功,该隐藏的按钮没有隐藏. 解决方法,在子页面添加一下js代码即可.链接的 ...

  2. IOS自带输入法中文不触发KEYUP事件导致vue双向绑定错误问题

    先上图: 可以看到输入框中的内容和弹出框的内容不一致, <input class="am-fr labRight" id="txcode" type=&q ...

  3. Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解

    不多说,直接上干货! Ubuntukylin-14.04-desktop(带分区)安装步骤详解 Ubuntu14.04安装之后的一些配置 Ubuntukylin-14.04-desktop( 不带分区 ...

  4. Ubuntukylin-14.04-desktop(带分区)安装步骤详解

    不多说,直接上干货! 成功! Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解 Ubuntu1 ...

  5. [原] corePlot 类库与iOS自带类库使用方法对比(很多开源代码都有这个特点)

    ——人类最倚重的是自己的“以往经验”.—— 我们直接看一下在corePlot 类库和iOS自带类中为一个控件设置文本显示格式的实现.   * corePlot 类库中,为一个对象设置标题显示格式 , ...

  6. iOS自带TTS技术的实现即语音播报

    文本转语音技术, 也叫TTS, 是Text To Speech的缩写. iOS如果想做有声书等功能的时候, 会用到这门技术. 一,使用iOS自带TTS需要注意的几点: iOS7之后才有该功能 需要 A ...

  7. 【ODPS】阿里云ODPS中带分区的表操作

    1.创建分区表: 分区表有自己的分区列,而分区表则没有. public static void createTableWithPartition(Odps odps, String createTab ...

  8. iOS自带地图纠偏问题

    …………纠偏 篇………….. 1. 涉及接口:<CoreLocation/CoreLocation.h> 2. 核心代码解读: if ([CLLocationManager locatio ...

  9. vue ios自带拼音全键输入法模糊查询兼容性问题

    ios的自带拼音全键会在输入框中输入拼音,直接在输入框用@keyup="autoInput()"的话,在监听输入事件的时候安卓显示正常, ios就会出现输入显示数据不灵敏 解决办法 ...

随机推荐

  1. js+ canvas 实现人物走动

    在网上看了一篇管道工玛利亚走动的图片,感觉人物走动的太生涩了,就写了一下代码改动一下: js 代码: //定义数组图片集合 var marios = new Array("image/QQ截 ...

  2. ChrisRenke/DrawerArrowDrawable源代码解析

    转载请注明出处http://blog.csdn.net/crazy__chen/article/details/46334843 源代码下载地址http://download.csdn.net/det ...

  3. 利用keytool颁发https证书方法

    1.首先生成私有认证机构 命令:keytool -genkeypair -alias CAname   补充:keytool -list 命令增加 -v 可以查看CA详细信息 2.然后生成私有证书 命 ...

  4. Android Studio 一些注意事项(自用,不定期更新)

    1,Android Studio 版本的选择 写这篇的时候,官方版本已经到了 v3.2.0,而我习惯使用的版本是 v2.3.1,因为这个版本有自带sdk的安装版,比较方便, 同时,v2.3.1 新建项 ...

  5. JQuery学习系列篇(二)

    1.事件切换函数 hover([over],out); over鼠标移动到元素上要触发的函数,out鼠标移出元素要触发的函数. 2.togger 如果元素是可见的,切换为隐藏的:如果元素是隐藏的,切换 ...

  6. Route学习笔记

    前言 UrlRoutingModule.class:这块的代码关联了上一篇中路由部分的一个详细说明 一:Route的讲解 1. 路由模板匹配 添加路由: MapRoute 剔除的路由:IgnoreRo ...

  7. iOS 内网内测应用发布

    之前测试时,iOS 开发会把测试版本上传到蒲公英上,可以很方便的获取.后来认为不安全,万一测试版泄露了会有风险,就又回到了解放前,测试跑到开发那里编包.想过把手机越狱安装开发的编的 ipa 包,这样测 ...

  8. Python 之 入门须知

    1.Python2.0不支持中文,3.0支持 2.版本问题

  9. DB2导出表结构、表数据小结

    一.DB2命令行导出数据库全库表结构 ① Win+R进入到DB2安装目录的BIN目录下,执行命令:DB2CMD,进入到DB2 CLP窗口. 命令:DB2CMD ② 创建一个data文件夹 命令:MKD ...

  10. ajax返回值

    前端: <html> <head> <meta name="viewport" content="width=device-width&qu ...