BRAddressPickerView.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // BRAddressPickerView.h
  3. // BRPickerViewDemo
  4. //
  5. // Created by renbo on 2017/8/11.
  6. // Copyright © 2017 irenb. All rights reserved.
  7. //
  8. // 最新代码下载地址:https://github.com/91renb/BRPickerView
  9. #import "BRBaseView.h"
  10. #import "BRAddressModel.h"
  11. NS_ASSUME_NONNULL_BEGIN
  12. /// 地址选择器类型
  13. typedef NS_ENUM(NSInteger, BRAddressPickerMode) {
  14. /** 显示【省市区】(默认) */
  15. BRAddressPickerModeArea,
  16. /** 显示【省市】 */
  17. BRAddressPickerModeCity,
  18. /** 显示【省】 */
  19. BRAddressPickerModeProvince
  20. };
  21. typedef void(^BRAddressResultBlock)(BRProvinceModel * _Nullable province, BRCityModel * _Nullable city, BRAreaModel * _Nullable area);
  22. @interface BRAddressPickerView : BRBaseView
  23. /**
  24. //////////////////////////////////////////////////////////////////////////
  25. ///
  26. /// 【用法一】
  27. /// 特点:灵活,扩展性强(推荐使用!)
  28. ///
  29. ////////////////////////////////////////////////////////////////////////*/
  30. /** 地址选择器显示类型 */
  31. @property (nonatomic, assign) BRAddressPickerMode pickerMode;
  32. /** 默认选中的位置(1.传索引数组,如:@[@10, @0, @4]) */
  33. @property (nullable, nonatomic, copy) NSArray <NSNumber *> *selectIndexs;
  34. /** 默认选中的位置(2.传值数组,如:@[@"浙江省", @"杭州市", @"西湖区"]) */
  35. @property (nullable, nonatomic, copy) NSArray <NSString *> *selectValues;
  36. /** 选择结果的回调 */
  37. @property (nullable, nonatomic, copy) BRAddressResultBlock resultBlock;
  38. /** 滚动选择时触发的回调 */
  39. @property (nullable, nonatomic, copy) BRAddressResultBlock changeBlock;
  40. /**
  41. * 地区数据源(不传或为nil,默认就获取本地 BRCity.json 文件的数据)
  42. * 1.可以传 JSON数组,要注意 层级结构 和 key 要与 BRCity.json 保持一致
  43. * 2.可以传 模型数组(NSArray <BRProvinceModel *> * 类型),自己解析数据源 只需要注意层级结构就行
  44. */
  45. @property (nullable, nonatomic, copy) NSArray *dataSourceArr;
  46. /// 初始化地址选择器
  47. /// @param pickerMode 地址选择器显示类型
  48. - (instancetype)initWithPickerMode:(BRAddressPickerMode)pickerMode;
  49. /// 弹出选择器视图
  50. - (void)show;
  51. /// 关闭选择器视图
  52. - (void)dismiss;
  53. //================================================= 华丽的分割线 =================================================
  54. /**
  55. //////////////////////////////////////////////////////////////////////////
  56. ///
  57. /// 【用法二】:快捷使用,直接选择下面其中的一个方法进行使用
  58. /// 特点:快捷,方便
  59. ///
  60. ////////////////////////////////////////////////////////////////////////*/
  61. /**
  62. * 1.显示地址选择器
  63. *
  64. * @param selectIndexs 默认选中的值(传索引数组,如:@[@10, @0, @4])
  65. * @param resultBlock 选择后的回调
  66. *
  67. */
  68. + (void)showAddressPickerWithSelectIndexs:(nullable NSArray <NSNumber *> *)selectIndexs
  69. resultBlock:(nullable BRAddressResultBlock)resultBlock;
  70. /**
  71. * 2.显示地址选择器
  72. *
  73. * @param mode 地址选择器显示类型
  74. * @param selectIndexs 默认选中的值(传索引数组,如:@[@10, @0, @4])
  75. * @param isAutoSelect 是否自动选择,即滚动选择器后就执行结果回调,默认为 NO
  76. * @param resultBlock 选择后的回调
  77. *
  78. */
  79. + (void)showAddressPickerWithMode:(BRAddressPickerMode)mode
  80. selectIndexs:(nullable NSArray <NSNumber *> *)selectIndexs
  81. isAutoSelect:(BOOL)isAutoSelect
  82. resultBlock:(nullable BRAddressResultBlock)resultBlock;
  83. /**
  84. * 3.显示地址选择器
  85. *
  86. * @param mode 地址选择器显示类型
  87. * @param dataSource 地区数据源
  88. * @param selectIndexs 默认选中的值(传索引数组,如:@[@10, @0, @4])
  89. * @param isAutoSelect 是否自动选择,即滚动选择器后就执行结果回调,默认为 NO
  90. * @param resultBlock 选择后的回调
  91. *
  92. */
  93. + (void)showAddressPickerWithMode:(BRAddressPickerMode)mode
  94. dataSource:(nullable NSArray *)dataSource
  95. selectIndexs:(nullable NSArray <NSNumber *> *)selectIndexs
  96. isAutoSelect:(BOOL)isAutoSelect
  97. resultBlock:(nullable BRAddressResultBlock)resultBlock;
  98. @end
  99. NS_ASSUME_NONNULL_END