美团HD(5)-选择城市
DJSelectCityViewController.m
#import "DJSelectCityViewController.h"
#import "DJConstantValue.h"
#import "DJCityGroup.h"
#import "MJExtension.h" @interface DJSelectCityViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate> /** 城市组列表 */
@property (nonatomic,strong) NSMutableArray *cityGroups;
@property (weak, nonatomic) IBOutlet UITableView *cityTableView; @end @implementation DJSelectCityViewController - (void)viewDidLoad {
[super viewDidLoad]; self.title = @"选择城市";
// 设置右侧索引栏字体颜色
self.cityTableView.sectionIndexColor = [UIColor blackColor]; [self setupNavLeftItem];
[self loadCityData]; } - (void)setupNavLeftItem { UIBarButtonItem *closeItem = [UIBarButtonItem itemWithTarget:self action:@selector(close) image:@"btn_navigation_close" highlighImage:@"btn_navigation_close_hl"]; self.navigationItem.leftBarButtonItem = closeItem; } /** 加载城市数据 */
- (void)loadCityData { self.cityGroups = [DJCityGroup mj_objectArrayWithFilename:@"cityGroups.plist"]; } /** 关闭当前界面 */
- (void)close { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - UITableView 数据源方法 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.cityGroups.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { DJCityGroup *cityGroup = self.cityGroups[section];
return cityGroup.cities.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"cityGroup";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
DJCityGroup *cityGroup = self.cityGroups[indexPath.section];
NSString *cityName = cityGroup.cities[indexPath.row]; cell.textLabel.text = cityName; return cell;
} #pragma mark - tableView 代理方法 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { DJCityGroup *cityGroup = self.cityGroups[section];
return cityGroup.title; } - (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView { return [self.cityGroups valueForKeyPath:@"title"]; } #pragma mark - UISearchBar 代理方法 /** SearchBar开始编辑 */
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { // 隐藏导航栏
[self.navigationController setNavigationBarHidden:YES animated:YES]; } /** SearchBar结束编辑 */
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { // 显示导航栏
[self.navigationController setNavigationBarHidden:NO animated:YES]; } @end
最终效果:

美团HD(5)-选择城市的更多相关文章
- LOJ #6192. 「美团 CodeM 复赛」城市网络 (树上倍增)
#6192. 「美团 CodeM 复赛」城市网络 内存限制:64 MiB 时间限制:500 ms 标准输入输出 题目描述 有一个树状的城市网络(即 nnn 个城市由 n−1n-1n−1 条道路连接 ...
- LibreOJ #6192. 「美团 CodeM 复赛」城市网络
#6192. 「美团 CodeM 复赛」城市网络 内存限制:64 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: sqc 提交提交记录统计讨论测试数据 题目描 ...
- 美团 CodeM 复赛」城市网络
美团 CodeM 复赛」城市网络 内存限制:64 MiB时间限制:500 ms标准输入输出 题目描述 有一个树状的城市网络(即 nnn 个城市由 n−1n-1n−1 条道路连接的连通图),首都为 11 ...
- h5手机端下拉选择城市
<!doctype html><html> <head> <meta http-equiv="Content-Type& ...
- jquery实现输入框聚焦,键盘上下键选择城市
在最近有个项目中 需要实现当文本框聚焦的时候,可以键盘上下键选择内容,按enter键的时候,把内容传到输入框中,如图所示: 实现代码如下: /** *输入框聚焦,键盘上下键选择城市 */ ;(func ...
- 每天一个JavaScript实例-动态省份选择城市
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- jQuery 选择城市,显示对应的即时时区时间
因客户需要,我们CRM系统中,jQuery 弄个时区插件 如图: HTML: <div id="cityDate"> <i class="P_arrow ...
- 美团HD(9)-监听点击城市
DJSelectCityViewController.h // 点击城市发出通知 - (void)tableView:(UITableView *)tableView didSelectRowAtIn ...
- 【代码笔记】iOS-先选择城市,然后,跳转Tabbar
一,效果图. 二,工程图. 三,代码. ChooseCityViewController.h #import <UIKit/UIKit.h> @interface ChooseCityVi ...
随机推荐
- Apache的详细安装教程和遇到的问题解决方案
Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一 (一)Apache安装软件下载 1.访问 ...
- php Zend Opcache,xcache,eAccelerator缓存优化详解(具体根据个人需要选择其一即可,功能都一样切勿重复选择)
载入 XCache 模块 引用 ;; 安装成 zend extension (推荐), 路径一般是 "$extension_dir/xcache.so" zend_extensio ...
- python-socket模块
socket server #!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('127.0.0.1',9999 ...
- docker 基础使用
搜索某个镜像: docker search busybox 拉取: docker pull busybox 查看: docker images 启动并运行: docker run -it b ...
- [转载]跨域iframe高度自适应
场景: 经常会有这样的需求,跟外部合作伙伴合作,要嵌入别人的页面,这时候就需要高度自适应了,在这种跨域的情况下如何解决呢? 解决: 在iframe(合作伙伴的页面,称为P页面)中创建一个隐藏的ifra ...
- 基本shell编程【3】- 常用的工具awk\sed\sort\uniq\od
awk awk是个很好用的东西,大量使用在linux系统分析的结果展示处理上.并且可以使用管道, input | awk '' | output 1.首先要知道形式 awk 'command' fi ...
- js form 表达关于onpress 的一个问题
<form id="search-form" method="get" action="/search"> <fields ...
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- [LeetCode] Design Twitter 设计推特
Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and ...
- Sprng ecache
Ehcache是一种广泛使用的开源java分布式缓存,它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点. 主要的 ...