Giter Site home page Giter Site logo

addresspickerviewdemo's Introduction

AddressPickerViewDemo

这是一个地址选择工具类,提供三种模式可供选择.

核心类

#import "AddressPickerView.h"

数据源类

#import "AddressDataSource.h"

在控制器中的调用

//用一个按钮的点击事件来调起地址选择器
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(50, 30, 100, 50);
_button.backgroundColor = [UIColor redColor];
[_button setTitle:@"Show" forState:UIControlStateNormal];
[_button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_button];

//调用方法(核心)根据后面的枚举,传入不同的枚举,展示不同的模式
    _addressPickerView = [[AddressPickerView alloc] initWithkAddressPickerViewModel:kAddressPickerViewModelAll];
    //默认为NO
    //_addressPickerView.showLastSelect = YES;
    _addressPickerView.cancelBtnBlock = ^() {
        //移除掉地址选择器
        [weakSelf.addressPickerView hiddenInView];
    };
    _addressPickerView.sureBtnBlock = ^(NSString *province, NSString *city, NSString *district, NSString *addressCode) {
        //返回过来的信息在后面的这四个参数中,使用的时候要做非空判断(province和addressCode为必返回参数,可以不做非空判断)
        
        NSString *showString;
        
        if (city != nil) {
            showString = [NSString stringWithFormat:@"%@-%@", province, city];
        }else{
            showString = province;
        }
        if (district != nil) {
            showString = [NSString stringWithFormat:@"%@-%@", showString, district];
        }
        
        weakSelf.addressNameLab.text = [NSString stringWithFormat:@"地址:%@", showString];
        weakSelf.addressCodeLab.text = [NSString stringWithFormat:@"地区编码:%@", addressCode];
        //移除掉地址选择器
        [weakSelf.addressPickerView hiddenInView];
    };

//按钮点击方法的实现
- (void)buttonClick:(id)sender {
    //展示地址选择器
    [_addressPickerView showInView:self.view];
}

addresspickerviewdemo's People

Contributors

xihelaobo avatar

Stargazers

selice avatar BobooO avatar Iran-Q avatar web avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.