Giter VIP home page Giter VIP logo

cfcitypickervc's Introduction

image



Charlin出框架的目标:简单、易用、实用、高度封装、绝对解耦!




CFCityPickerVC(关注信息公告牌


城市选取控制器

.Swift 1.2

.Xcode 6.3




框架说明

注:请直接拖拽CFCityPickerVC文件夹到你的项目即可,由于城市具有**特色,所以只有中文版本。不支持pod。

1.原创框架,无需任何依赖,直接即可使用。
2.支持自动定位。
3.支持自定义热门城市。
4.支持自定义当前城市。
5.全部使用Closure回调,没有代理!
6.支持ios 7.0及以上,支持横竖屏!




功能演示

####1.基本展示 image

####2.索引展示:索引快速定位 image

####3.城市选择与回调:closure回调,请注意控制台打印 image

####4.历史选择:请注意历史城市与其排序 image

####5.自定义检索:自动回调,历史记录同样可用 image

####6.横屏支持 image




使用说明



####1.导入 直接拖拽CFCityPickerVC文件夹到您项目中即可

由于是拖拽式,所以swift中的命名空间不能很好的发挥,所以框架有一定的前缀,不过在类的归属上, 我尽量使用了命名空间的原则。其中最明显的就是CityModel是使用了命名空间。

1.搜索框的cancel按钮如果需要中文,请添加中文多语言支持即可
2.iOS 8定位,请在info.plist 中添加NSLocationWhenInUseUsageDescription 说明文字



####2.model展示城市控制器 由于您的项目的导航栏肯定是定制的,所以我这里是让您自己来传您的NavVC,请不要直接modal框架中的CFCityPickerVC,不然会没有导航栏:

  let cityVC = CFCityPickerVC()
  //设置城市数据
  let cityModels = cityModelsPrepare()
  cityVC.cityModels = cityModels
  let navVC = UINavigationController(rootViewController: cityVC)
  navVC.navigationBar.barStyle = UIBarStyle.BlackTranslucent
  self.presentViewController(navVC, animated: true, completion: nil)

注:这里的设置城市数据,你数据可以来自网络,我这里来自plist,由于目前swift中一键字典转模型工具还没有完善,所以是手动解析。



####3.设置当前城市:直接城市名即可,请不要带有【市】字,如:成都

//设置当前城市
cityVC.currentCity = "成都"

注:当然你这里是可以不用设置的,框架有自动定位机制。如果你手动设置了当前城市,则不会触发自动定位。



####4.设置热门城市

  //设置热门城市
  cityVC.hotCities = ["北京","上海","广州","成都","杭州","重庆"]

注:同样注意不要带有【市】字



####5.城市选中事件回调:Closure回调,无代理

  //选中了城市
  cityVC.selectedCityModel = { (cityModel: CFCityPickerVC.CityModel) in
    println("您选中了城市: \(cityModel.name)")
  }




结束语

此框架基本是我前几天在去若尔盖草原旅游的漫长的长途汽车上完成的,在此纪念一下!




MIT

此框架基于MIT协议开源

cfcitypickervc's People

Contributors

charlinfeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cfcitypickervc's Issues

运行可以了,但是会报很多警告

2016-05-04 15:24:31.521 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545ad770 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1545985a0.height == UIView:0x1545903e0.height - 344>",
"<NSLayoutConstraint:0x1546434a0 V:|-(8)-[UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02'] (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x154642cb0 V:[UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02']-(15)-[CFCityPickerVC.CFCPContentView:0x154598c20]>",
"<NSLayoutConstraint:0x154637570 V:[CFCityPickerVC.CFCPContentView:0x154598c20]-(15)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x154629ee0 V:|-(10)-[CFCityPickerVC.CitySearchBar:0x1545906c0] (Names: '|':UIView:0x1545903e0 )>",
"<NSLayoutConstraint:0x154631d70 V:[CFCityPickerVC.CitySearchBar:0x1545906c0(36)]>",
"<NSLayoutConstraint:0x154631dc0 V:[CFCityPickerVC.CitySearchBar:0x1545906c0]-(0)-| (Names: '|':UIView:0x1545903e0 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154642cb0 V:[UILabel:0x1547078e0'当前城市']-(15)-[CFCityPickerVC.CFCPContentView:0x154598c20]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.523 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545ad770 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1545985a0.height == UIView:0x1545903e0.height - 344>",
"<NSLayoutConstraint:0x154629ee0 V:|-(10)-[CFCityPickerVC.CitySearchBar:0x1545906c0] (Names: '|':UIView:0x1545903e0 )>",
"<NSLayoutConstraint:0x154631d70 V:[CFCityPickerVC.CitySearchBar:0x1545906c0(36)]>",
"<NSLayoutConstraint:0x154631dc0 V:[CFCityPickerVC.CitySearchBar:0x1545906c0]-(0)-| (Names: '|':UIView:0x1545903e0 )>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154631dc0 V:[CFCityPickerVC.CitySearchBar:0x1545906c0]-(0)-| (Names: '|':UIView:0x1545903e0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.530 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545ade40 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1545985a0.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x1546434f0 UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02'.leading == CFCityPickerVC.CFCPContentView:0x154598c20.leading>",
"<NSLayoutConstraint:0x154642d40 H:|-(18)-[UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02'] (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x154642c60 H:[CFCityPickerVC.CFCPContentView:0x154598c20]-(30)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1546434f0 UILabel:0x1547078e0'当前城市'.leading == CFCityPickerVC.CFCPContentView:0x154598c20.leading>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.534 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x15471fa60 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x154704520.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x15470a330 UILabel:0x1547080e0'\U70ed\U95e8\U57ce\U5e02'.leading == CFCityPickerVC.CFCPContentView:0x1547082f0.leading>",
"<NSLayoutConstraint:0x15470a380 H:|-(18)-[UILabel:0x1547080e0'\U70ed\U95e8\U57ce\U5e02'] (Names: '|':CFCityPickerVC.HeaderItemView:0x154704520 )>",
"<NSLayoutConstraint:0x15470a420 H:[CFCityPickerVC.CFCPContentView:0x1547082f0]-(30)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x154704520 )>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15470a330 UILabel:0x1547080e0'热门城市'.leading == CFCityPickerVC.CFCPContentView:0x1547082f0.leading>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.538 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545b1900 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1547085d0.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x154709850 UILabel:0x154708770'\U5386\U53f2\U9009\U62e9'.leading == CFCityPickerVC.CFCPContentView:0x154708d60.leading>",
"<NSLayoutConstraint:0x1547098a0 H:|-(18)-[UILabel:0x154708770'\U5386\U53f2\U9009\U62e9'] (Names: '|':CFCityPickerVC.HeaderItemView:0x1547085d0 )>",
"<NSLayoutConstraint:0x154709940 H:[CFCityPickerVC.CFCPContentView:0x154708d60]-(30)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x1547085d0 )>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154709850 UILabel:0x154708770'历史选择'.leading == CFCityPickerVC.CFCPContentView:0x154708d60.leading>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.540 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x15462a040 H:|-(18)-[CFCityPickerVC.CitySearchBar:0x1545906c0] (Names: '|':UIView:0x1545903e0 )>",
"<NSLayoutConstraint:0x154629ac0 H:[CFCityPickerVC.CitySearchBar:0x1545906c0]-(20)-| (Names: '|':UIView:0x1545903e0 )>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154629ac0 H:[CFCityPickerVC.CitySearchBar:0x1545906c0]-(20)-| (Names: '|':UIView:0x1545903e0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.545 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x15471fa60 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x154704520.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x15470a380 H:|-(18)-[UILabel:0x1547080e0'\U70ed\U95e8\U57ce\U5e02'] (Names: '|':CFCityPickerVC.HeaderItemView:0x154704520 )>",
"<NSLayoutConstraint:0x15470a510 H:[UIView:0x154703d40]-(0)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x154704520 )>",
"<NSLayoutConstraint:0x15470a560 H:[UILabel:0x1547080e0'\U70ed\U95e8\U57ce\U5e02']-(6)-[UIView:0x154703d40]>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15470a560 H:[UILabel:0x1547080e0'热门城市']-(6)-[UIView:0x154703d40]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.546 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545b1900 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1547085d0.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x1547098a0 H:|-(18)-[UILabel:0x154708770'\U5386\U53f2\U9009\U62e9'] (Names: '|':CFCityPickerVC.HeaderItemView:0x1547085d0 )>",
"<NSLayoutConstraint:0x154709a30 H:[UIView:0x154708ab0]-(0)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x1547085d0 )>",
"<NSLayoutConstraint:0x154709a80 H:[UILabel:0x154708770'\U5386\U53f2\U9009\U62e9']-(6)-[UIView:0x154708ab0]>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154709a80 H:[UILabel:0x154708770'历史选择']-(6)-[UIView:0x154708ab0]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-05-04 15:24:31.548 CFCityPickerVC[17697:4651979] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x1545ade40 h=-&- v=-&- CFCityPickerVC.HeaderItemView:0x1545985a0.width == UIView:0x1545903e0.width>",
"<NSLayoutConstraint:0x154642d40 H:|-(18)-[UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02'] (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x1546375c0 H:[UIView:0x154598980]-(0)-| (Names: '|':CFCityPickerVC.HeaderItemView:0x1545985a0 )>",
"<NSLayoutConstraint:0x154704e80 H:[UILabel:0x1547078e0'\U5f53\U524d\U57ce\U5e02']-(6)-[UIView:0x154598980]>",
"<NSLayoutConstraint:0x1545b3890 'UIView-Encapsulated-Layout-Width' H:[UIView:0x1545903e0(0)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x154704e80 H:[UILabel:0x1547078e0'当前城市']-(6)-[UIView:0x154598980]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

currentCity error

设置currentCity后出现fatal error: unexpectedly found nil while unwrapping an Optional value

image

image

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.