在ViewController文件中创建添加地址界面:

@property(nonatomic,strong)UILabel *selectAreaLabel;//地区显示
@property(nonatomic,strong)UITextField *nameTextF;//收货人
@property(nonatomic,strong)UITextField *phoneTextF;//联系方式
@property(nonatomic,strong)UITextField *addressTextF;//详细地址
@property(nonatomic,copy)NSString *switchStr;//选择按钮值
@property(nonatomic,strong)SelectAreaView *selectView;//选择地区视图
@property(nonatomic,strong)UIView *smallBgView;//选择地区下方白色区域
@property(nonatomic,strong)NSMutableArray *dataArray1;//地址列表数据

@property(nonatomic,strong)NSMutableArray *areaInfoArray;//返回地址相关信息

在数据请求成功后,添加半透明背景,添加可选择的地区列表:

if (success)
        {
            NSArray *itemArray = [[resultDic[@"ITEMS"] reverseObjectEnumerator] allObjects];
            for (NSDictionary *dic in itemArray)
            {
                [_dataArray1 addObject:dic];
            }
            _smallBgView = [[UIView alloc] initWithFrame:CGRectMake(0, f_Device_h, f_Device_w, f_Device_h)];
            _smallBgView.backgroundColor = [UIColor darkGrayColor];
            _smallBgView.alpha = 0.8;
            [self.view addSubview:_smallBgView];
            _selectView = [[SelectAreaView alloc] initWithProvinceList:CGRectMake(0, f_Device_h, f_Device_w, f_Device_h/3*2) dataArray:_dataArray1];
            [self.view addSubview:_selectView];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(downSmallBgView:) name:@"downSmallBgV" object:nil];
        }

添加一个通知实现当地区选择完成落下来后,执行的方法

#pragma mark --- 接收到通知
-(void)downSmallBgView:(NSNotification *)notifi
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    _smallBgView.frame = CGRectMake(0, f_Device_h, f_Device_w, f_Device_h);
    _selectView.frame = CGRectMake(0, f_Device_h, f_Device_w, f_Device_h/3*2);
    [UIView commitAnimations];
    
    NSDictionary *dic = [notifi userInfo];
    _areaInfoArray = [NSMutableArray arrayWithArray:dic[@"areaArray"]];
    if (_areaInfoArray.count > 0)
    {
        NSMutableString *muStr = [NSMutableString new];
        for (NSDictionary *areaDic in _areaInfoArray)
        {
            NSString *nameStr = areaDic[@"adName"];
            if (nameStr.length >0)
            {
                [muStr appendString:nameStr];
            }
        }
        _selectAreaLabel.text = muStr;
    }
    else
    {
        _selectAreaLabel.text = @"无";
    }
}

自定义一个选择视图

//初始化视图方法
-(id)initWithProvinceList:(CGRect)frame dataArray:(NSMutableArray *)aDataArray
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.itemDic = @{@"adCode":@"",@"adName":@"",@"id":@"",@"parentId":@""};
        self.areaMuArray = [NSMutableArray arrayWithObjects:_itemDic,_itemDic,_itemDic, nil];
        self.dataArray1 = [NSMutableArray arrayWithArray: aDataArray];
        self.dataArray2 = [NSMutableArray new];
        self.dataArray3 = [NSMutableArray new];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, f_Device_w, 40)];
        titleLabel.text = @"选择地区";
        titleLabel.textColor = [UIColor darkGrayColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:titleLabel];
        
        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        closeBtn.frame = CGRectMake(f_Device_w-40, 5, 30, 30);
        [closeBtn setBackgroundImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
        [self addSubview:closeBtn];
        [closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        //省市区按钮
        for (int i = 0; i < 3; i ++)
        {
            UIButton *sBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            sBtn.frame = CGRectMake(20+50*i, 45, 50, 29);
            if (i == 0)
            {
                [sBtn setTitle:@"请选择" forState:UIControlStateNormal];
            }
            sBtn.titleLabel.font = [UIFont systemFontOfSize:13];
            sBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
            [sBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            sBtn.tag = i+10;
            [sBtn addTarget:self action:@selector(selectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:sBtn];
        }
        
        //分割
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 74, f_Device_w, 1)];
        lineView.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:lineView];
        
        _scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 75, f_Device_w, f_Device_h-f_Device_h/3-75)];
        _scrollV.showsHorizontalScrollIndicator = NO;
        _scrollV.pagingEnabled = YES;
        [self addSubview:_scrollV];
        
        for (int i = 0; i < 3; i ++)
        {
            UITableView *tableViewW = [[UITableView alloc] initWithFrame:CGRectMake(f_Device_w*i, 0, f_Device_w, f_Device_h-f_Device_h/3-75) style:UITableViewStylePlain];
            tableViewW.delegate = self;
            tableViewW.dataSource = self;
            tableViewW.rowHeight = 30;
            tableViewW.tag = i+1;
            tableViewW.separatorStyle = UITableViewCellSeparatorStyleNone;
            [_scrollV addSubview:tableViewW];
        }
        
    }
    return self;
}

当选择地区后,执行的方法

#pragma mark --- 选中后执行方法
//参数说明:1:上一个表格数组,2:点击的是第几行数据,3:标题按钮的tag值,4:滑动视图有几个f_Device_w,5:下一个表格数组
-(void)showSelectViewArray1:(NSMutableArray *)aDataArray1 indexPathRow:(int)aRow buttonTag1:(int)aTag1 xPoint:(int)aXi dataArray2:(NSMutableArray *)aDataArray2
{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:aDataArray1[aRow]];
    UIButton *buttonN1 = (UIButton *)[self viewWithTag:aTag1];
    [buttonN1 setTitle:dic[@"adName"] forState:UIControlStateNormal];
    [buttonN1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [_areaMuArray replaceObjectAtIndex:aXi-2 withObject:dic];
    
    [self cityListHttpRequestIdStr:dic[@"id"] dataArray2:aDataArray2 buttonTag:aTag1 tableViewTag:aXi];
}
#pragma mark --- 市县区数据请求
//参数说明:1:上一个表格数组中的id,2:下一个表格数组,3:标题按钮tag值,4:tableView的tag值
-(void)cityListHttpRequestIdStr:(NSString *)parentIdStr dataArray2:(NSMutableArray *)aDataArray2 buttonTag:(int)btnTag tableViewTag:(int)aTag

效果图:

    

仿京东商城选择地区样式详细讲解源码Demo:http://download.csdn.net/detail/hbblzjy/9603813

iOS模仿京东商城中的选择地区样式的更多相关文章

  1. 商城项目实战 | 2.1 Android 仿京东商城——自定义 Toolbar (一)

    前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 现在很多的 APP 里面都有自己的自定义风格,特别是京东商城中自 ...

  2. 商城项目实战 | 1.1 Android 仿京东商城底部布局的选择效果 —— Selector 选择器的实现

    前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 京东商城的底部布局的选择效果看上去很复杂,其实很简单,这主要是要 ...

  3. [js开源组件开发]js手机联动选择地区仿ios 开源git

    js手机联动选择地区 前言:由于网上找到了一个mobiscrool,比较全,但是不开源,只能试用15天,正式版竟然要三千块钱,穷人只能自己动手,写了个只针对弹窗地区选择的. 本站点所有的资源均在git ...

  4. iOS仿京东分类菜单之UICollectionView内容

    在上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列 ...

  5. ThinkPHP3.2开发仿京东商城项目实战视频教程

    ThinkPHP3.2仿京东商城视频教程实战课程,ThinkPHP3.2开发大型商城项目实战视频 第一天 1.项目说明 2.时间插件.XSS过滤.在线编辑器使用 3.商品的删除 4.商品的修改完成-一 ...

  6. Python网络爬虫——京东商城商品列表

    Python_网络爬虫--京东商城商品列表 最近在拓展自己知识面,想学习一下其他的编程语言,处于多方的考虑最终选择了Python,Python从发布之初就以庞大的用户集群占据了编程的一席之地,pyth ...

  7. Android 深入ViewPager补间动画,实现类京东商城首页广告Banner切换效果

    如有转载,请声明出处: 时之沙: http://blog.csdn.net/t12x3456 某天看到京东商城首页的滑动广告的Banner,在流动切换的时候有立体的动画效果,感觉很有意思,然后研究了下 ...

  8. iOS已发布应用中对异常信息捕获和处理

    iOS已发布应用中对异常信息捕获和处理 iOS开发中我们会遇到程序抛出异常退出的情况,如果是在调试的过程中,异常的信息是一目了然,但是如果是在已经发布的程序中,获取异常的信息有时候是比较困难的. iO ...

  9. 商城项目实战 | 2.2 Android 仿京东商城——自定义 Toolbar (二)

    本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 上一篇文章<商城项目实战 | 2.1 Android 仿京东商城 ...

随机推荐

  1. You And Me 不见不散!

    泰戈尔说: 有一个夜晚,我烧毁了所有的记忆, 从此我的梦就透明了: 有个早晨我扔掉了所有的昨天, 从此我的脚步就轻盈了! 越过山丘,才发现无人等候! 有段话最近很流行:20多岁的你,迷茫又着急,你想要 ...

  2. Nginx+Tomca+Redis实现负载均衡、资源分离、session共享

    目标实现:Nginx作为负载均衡后端多Tomcat实例,通过Redis实现Session共享. 操作系统环境:CentOS 6.8 SSH:SecureCRT 其中 Nginx服务:80端口 Tomc ...

  3. 手写JAVA虚拟机(三)——搜索class文件并读出内容

    查看手写JAVA虚拟机系列可以进我的博客园主页查看. 前面我们介绍了准备工作以及命令行的编写.既然我们的任务实现命令行中的java命令,同时我们知道java命令是将class文件(字节码)转换成机器码 ...

  4. js保留两位小数数字

    /* * @descript: 保留两位小数,如果小数点大于两位小数,就向上取值保留两位小数<br/> * @time 2016-07-13 */function mathCeil(num ...

  5. 深入浅出低功耗蓝牙(BLE)协议栈

    深入浅出低功耗蓝牙(BLE)协议栈 BLE协议栈为什么要分层?怎么理解蓝牙"连接"?如果蓝牙协议只有ATT没有GATT会发生什么? 协议栈框架 一般而言,我们把某个协议的实现代码称 ...

  6. git 撤销没有提交的变化

    参考: https://stackoverflow.com/questions/5807137/how-to-revert-uncommitted-changes-including-files-an ...

  7. 给定 n×n 的实数矩阵,每行和每列都是递增的,求这 n^2 个数的中位数。

    #define COL 4 #define ROW 4 int findMedian(int matrix[][COL], int row, int col) { int* arr = new int ...

  8. Dynamics CRM2016 Web API之获取查找字段的text及选项集的text

    本篇再来介绍个web api的功能,关于lookup的text这里只是略带,因为有expand,现有的web api就能实现,主要提的是选项集的text,我们通过基本的查询api查出来的字段值只带有v ...

  9. Spark:Spark 编程模型及快速入门

    http://blog.csdn.net/pipisorry/article/details/52366356 Spark编程模型 SparkContext类和SparkConf类 代码中初始化 我们 ...

  10. Android的Intent机制详解

    Intent 是一个消息传递对象,您可以使用它从其他应用组件请求操作.尽管 Intent 可以通过多种方式促进组件之间的通信,但其 基本用例主要包括以下三个: 启动 Activity: Activit ...