1. //
  2. // MainViewController.m
  3. // UI10_带分区的省市区
  4. //
  5. // Created by dllo on 15/8/11.
  6. // Copyright (c) 2015年 zhozhicheng. All rights reserved.
  7. //
  8. #import "MainViewController.h"
  9. #import "SecondViewController.h"
  10. @interface MainViewController ()<UITableViewDataSource,UITableViewDelegate>
  11. @property(nonatomic,retain)NSMutableArray *proArr;
  12. @property(nonatomic,retain)UITableView *tableView;
  13. @end
  14. @implementation MainViewController
  15. -(void)dealloc
  16. {
  17. [_proArr release];
  18. [super dealloc];
  19. }
  20. #pragma mark 假设在初始化方法里使用self.view,此时还没有创建self.view系统会自己主动调用loadview,创建一个self.view,从而改变VC的运行流程,所以我们仅仅在初始化方法里初始化容器等数据部分,而不创建视图
  21. //初始化方法
  22. -(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  23. {
  24. self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  25. if (self) {
  26. [self createData];
  27. }return self;
  28. }
  29. -(void)createData
  30. {
  31. //文件的路径
  32. NSString *path=@"/Users/dllo/Desktop/上课内容 /UI10_带分区的省市区/UI10_带分区的省市区/area.txt";
  33. NSString *str =[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
  34. NSArray *strArr=[str componentsSeparatedByString:@"\n"];
  35. self.proArr=[NSMutableArray array];
  36. //省市区数组
  37. for(NSString *temp in strArr){
  38. if (![temp hasPrefix:@" "]) {
  39. NSMutableDictionary *proDic=[NSMutableDictionary dictionary];
  40. [proDic setObject:temp forKey:@"proName"];
  41. NSMutableArray *cityArr=[NSMutableArray array];
  42. [proDic setObject:cityArr forKey:@"cityArr"];
  43. [self.proArr addObject:proDic];
  44. }else if ([temp hasPrefix:@" "] && ![temp hasPrefix:@" "])
  45. {
  46. NSMutableDictionary *cityDic=[NSMutableDictionary dictionary];
  47. [cityDic setValue:temp forKey:@"cityName"];
  48. NSMutableArray *zoneArr=[NSMutableArray array];
  49. [cityDic setValue:zoneArr forKey:@"zoneArr"];
  50. NSMutableDictionary *proDic=[self.proArr lastObject];
  51. NSMutableArray *cityArr=proDic[@"cityArr"];
  52. [cityArr addObject:cityDic];
  53. }else
  54. {
  55. NSMutableDictionary *proDic=[self.proArr lastObject];
  56. NSMutableArray *cityArr=proDic[@"cityArr"];
  57. NSMutableDictionary *cityDic=[cityArr lastObject];
  58. NSMutableArray *zoneArr=cityDic[@"zoneArr"];
  59. [zoneArr addObject:temp];
  60. }
  61. }
  62. }
  63. - (void)viewDidLoad {
  64. [super viewDidLoad];
  65. // Do any additional setup after loading the view.
  66. self.view.backgroundColor=[UIColor cyanColor];
  67. self.navigationController.navigationBar.translucent=NO;
  68. self.navigationItem.title=@"省";
  69. self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height -64) style:UITableViewStylePlain];
  70. self.tableView.dataSource=self;
  71. self.tableView.delegate=self;
  72. [self.view addSubview:self.tableView];
  73. [self.tableView release];
  74. }
  75. //
  76. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  77. {
  78. NSMutableArray *cityArr =self.proArr[section][@"cityArr"];
  79. return cityArr.count;
  80. }
  81. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  82. {
  83. return self.proArr.count;
  84. }
  85. //很多其它
  86. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  87. {
  88. UIView *newView=[[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)] autorelease];
  89. newView.backgroundColor=[UIColor yellowColor];
  90. UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
  91. [newView addSubview:label];
  92. [label release];
  93. label.text=self.proArr[section][@"proName"];
  94. UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
  95. button.frame = CGRectMake(300, 0, 40, 20);
  96. [button setTitle:@"很多其它" forState:UIControlStateNormal];
  97. [newView addSubview:button];
  98. [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
  99. return newView;
  100. }
  101. -(void)click:(UIButton *)button
  102. {
  103. NSLog(@"da");
  104. }
  105. //创建cell,显示数据
  106. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  107. {
  108. static NSString *reuse=@"reuse";
  109. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse];
  110. if (!cell) {
  111. cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
  112. }
  113. //省字典
  114. NSMutableDictionary *proDic=self.proArr[indexPath.section];
  115. NSMutableArray *cityArr=proDic[@"cityArr"];
  116. cell.textLabel.text=cityArr[indexPath.row][@"cityName"];
  117. return cell;
  118. }
  119. //调到第二个页面
  120. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. SecondViewController *secondVC=[[SecondViewController alloc] init];
  123. [self.navigationController pushViewController:secondVC animated:YES];
  124. [secondVC release];
  125. }
  126. //分区头标题
  127. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  128. {
  129. return self.proArr[section][@"proName"];
  130. }
  131. - (void)didReceiveMemoryWarning {
  132. [super didReceiveMemoryWarning];
  133. // Dispose of any resources that can be recreated.
  134. }
  135. /*
  136. #pragma mark - Navigation
  137. // In a storyboard-based application, you will often want to do a little preparation before navigation
  138. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  139. // Get the new view controller using [segue destinationViewController].
  140. // Pass the selected object to the new view controller.
  141. }
  142. */
  143. @end
  1. //
  2. // SecondViewController.m
  3. // UI10_带分区的省市区
  4. //
  5. // Created by dllo on 15/8/11.
  6. // Copyright (c) 2015年 zhozhicheng. All rights reserved.
  7. //
  8. #import "SecondViewController.h"
  9. @interface SecondViewController ()
  10. @end
  11. @implementation SecondViewController
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. // Do any additional setup after loading the view.
  15. self.view.backgroundColor=[UIColor cyanColor];
  16. }
  17. - (void)didReceiveMemoryWarning {
  18. [super didReceiveMemoryWarning];
  19. // Dispose of any resources that can be recreated.
  20. }
  21. /*
  22. #pragma mark - Navigation
  23. // In a storyboard-based application, you will often want to do a little preparation before navigation
  24. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  25. // Get the new view controller using [segue destinationViewController].
  26. // Pass the selected object to the new view controller.
  27. }
  28. */
  29. @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. android mvp高速开发框架介绍(dileber使用之图片下载工具)

    这几天忙着工作- 今天抽时间又把框架的bug处理了一下--并且把volley的源代码改动了一下 android mvp框架:dileber(https://github.com/dileber/dil ...

  2. POJ1390 Blocks 【动态规划】

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4173   Accepted: 1661 Descriptio ...

  3. Xcode6 引入第三方静态库project的方法

    首先.介绍一下把在当前project中引入其它依赖project的方法: 第一:把其它项目project加入到现有project做法: 定义: FPro 现有project == 父project C ...

  4. Word技巧杂记(二)——批量修改修订格式并接受

    今天的题目好奇怪啊,呵呵,起因如下: 今天老婆在修改论文,她的老板提出一个非常**的要求——把Word中所有修订后的文字用特殊的字体(蓝色)标出来,然后再接受修订.我勒个去,明明有修订后的模式啊,为什 ...

  5. php静态函数的使用场景

    php静态函数的使用场景 场景 代码 <?php class Conductor{ public static $i = 100; public function sold(){ $a = se ...

  6. jquery分页点击后页面置顶

    前台: <a href="#" ><span id='top'></span></a> js中: 放在分页事件后,数据加载完成后 j ...

  7. 图片词典 Picture Dictionary

    图片词典/可视词典 Picture Dictionary 某些 APP 又有新功能可以加入了.

  8. 什么是CNN--Convolutional Neural Networks

    是近些年在机器视觉领域很火的模型,最先由 Yan Lecun 提出. 如果想学细节可以看 Andrej Karpathy 的 cs231n . How does it work? 给一张图片,每个圆负 ...

  9. 安装wampserver遇到的问题及解决方案

    丢失api-ms-win-crt-runtime-l1-1-0.dll 安装完wampserver,启动服务器的时候遇到一些问题,提示说缺失dll文件,如下图所示: 网上一搜,很多人出现过丢失api- ...

  10. Unity 动画系统(Mecanim) 术语及翻译 表格

    原文 翻译 Animation Clip 视频片段 Avatar 阿凡达 Retargeting 重定向 Rigging 绑定 skinning 蒙皮 Animator Component 动画组件 ...