美团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 ...
随机推荐
- 不同数据库,查询前n条数据的SQL语句
不同的数据库,支持的SQL语法略有不同,以下是不同数据库查询前n条数据的SQl语句 SQL Server(MSSQL) SELECT TOP n * FROM table_name ORACLE SE ...
- XP本地连接正常无法上网的解决方法
原文: http://www.doc88.com/p-599590609730.html
- Linux多线程学习总结
线程是程序中完成一个独立任务的完整执行序列,即一个可调度的实体:进程相当于运行中程序的一种抽象.根据运行环境的调度者的身份,线程可分为内核线程和用户线程.内核线程,在有的系统上称为LWP(Light ...
- C语言文法
C语言文法 源程序 → 外部声明 | 子程序(外部声明) 外部声明 → 函数定义| 函数声明 函数定义 → 类型标识符(复合句) 标识符类型 → 无类型 | 字符型 | 整型 | 浮点型 整型→ ...
- [LeetCode] Design Tic-Tac-Toe 设计井字棋游戏
Design a Tic-tac-toe game that is played between two players on a n x n grid. You may assume the fol ...
- 【经验之谈】Git使用之TortoiseGit配置VS详解
前言 上一篇<[经验之谈]Git使用之Windows环境下配置>: 安装 配置和使用 后记 关于vs中使用git网上的教程大家也可以找到,我当时配置的时候也是按照网上找的教程一步一步来的, ...
- 分分钟带你玩转 Web Services
当大型需求被数个公司分割开来,各公司系统相互交换数据的问题就会接踵而来. 毕竟是多家不同的公司的产品,研发开发语言.采用技术框架基本上是百花齐放. 怎样让自家系统提供的服务具有跨平台.跨语言.跨各种防 ...
- EF使用CodeFirst方式生成数据库&技巧经验
前言 EF已经发布很久了,也有越来越多的人在使用EF.如果你已经能够非常熟练的使用EF的功能,那么就不需要看了.本文意在将自己使用EF的方式记录下来备忘,也是为了给刚刚入门的同学一些指导.看完此文,你 ...
- Ubuntu 16.04 LAMP server 指南 - 配置 Apache2.4,PHP7,和MariaDB(而不是MySQL)
翻译自:https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/ 昨天在虚 ...
- FtpUtil
/* * 文件名:FtpUtil.java * 版权:Copyright 2000-2007 Huawei Tech. Co. Ltd. All Rights Reserved. * 描述: TopE ...