iOS UI10_带分区的省市区
来源:互联网 发布:java如何实现多线程 编辑:程序博客网 时间:2024/06/10 14:12
//// 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
0 0
- iOS UI10_带分区的省市区
- UI10_带分区的省市区
- UI10_省市区分区跳转版
- 带分区的省市区
- 带分区的省市区字典
- UI0_带分区的省市区
- 带分区的省市区字典数组
- UI 10 带分区的省市区......
- 带分区的UITableView的创建(省市区字典)
- 31.多种tableView和带分区的省市区显示
- UITableView中带分区的省市区字典,或一个页面出现全部省市区
- 创建带分区的表
- IOS初级省市区
- iOS省市区字典封装
- IOS 省市区三级联动
- iOS-中国省市区plist(续)UIPickerView的应用
- 用windows7自带的分区工具分区
- 用windows7自带的分区工具分割分区
- [Leetcode]Remove Duplicates from Sorted Array
- linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write
- JS学习第七天----语句
- Discovery(3)
- 利用SecureCRT上传、下载文件(使用sz与rz命令),超实用!
- iOS UI10_带分区的省市区
- Nginx
- Volley实现自定义的网络请求Implementing a Custom Request
- PHP_PHP开发框架-Phalcon
- Android生命周期
- SVN 版本冲突解决
- 黑马程序员--------------java基础----------------- 图形化界面
- 怎么知道Java class文件JDK编译的版本号
- iOS开发 - 苹果开发者账号那些事儿(二)