美团HD(3)-加载分类导航数据
DJHomeViewController.m
/** 设置导航栏左侧内容 */
- (void)setupLeftNavItem { // Logo
UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_meituan_logo"]];
UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithCustomView:logoView]; // 类别
DJNavItem *categoryView = [DJNavItem item];
[categoryView addTarget:self action:@selector(onCategoryNavItemDidClick)];
UIBarButtonItem *categoryItem = [[UIBarButtonItem alloc] initWithCustomView:categoryView];
self.categoryItem = categoryItem; // 地区
DJNavItem *areaView = [DJNavItem item];
[areaView addTarget:self action:@selector(onAreaNavItemDidClick)];
UIBarButtonItem *areaItem = [[UIBarButtonItem alloc] initWithCustomView:areaView];
self.areaItem = areaItem; // 排序
DJNavItem *sortView = [DJNavItem item];
[sortView addTarget:self action:@selector(onSortNavItemDidClick)];
UIBarButtonItem *sortItem = [[UIBarButtonItem alloc] initWithCustomView:sortView];
self.sortItem = sortItem; self.navigationItem.leftBarButtonItems = @[logoItem,categoryItem,areaItem,sortItem]; } #pragma mark - 导航按钮被点击
- (void)onCategoryNavItemDidClick { // 创建将要显示的Controller
DJCategoryViewController *categoryVC = [[DJCategoryViewController alloc] init];
// 设置控制器View的显示大小
categoryVC.preferredContentSize = CGSizeMake(, );
// 设置Modal类型
categoryVC.modalPresentationStyle = UIModalPresentationPopover;
// 获取Popover
UIPopoverPresentationController *categoryPopover = categoryVC.popoverPresentationController;
// 相对于哪个View来显示
categoryPopover.sourceView = self.categoryItem.customView;
// 显示位置
categoryPopover.sourceRect = self.categoryItem.customView.bounds;
// 设置popover箭头的显示方向
categoryPopover.permittedArrowDirections = UIPopoverArrowDirectionAny;
// 跳转
[self presentViewController:categoryVC animated:YES completion:nil]; }
DJNavDropView.m
#import "DJNavDropView.h"
#import "DJCategory.h" @interface DJNavDropView()<UITableViewDataSource,UITableViewDelegate> @property (weak, nonatomic) IBOutlet UITableView *mainTableView; @end @implementation DJNavDropView + (instancetype)dropView { return[[[NSBundle mainBundle] loadNibNamed:@"DJNavDropView" owner:nil options:nil] lastObject]; } - (void)setCategoryList:(NSArray *)categoryList { _categoryList = categoryList; // 刷新数据
[self.mainTableView reloadData]; } #pragma mark - TableView 数据源方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.categoryList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"category";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
} DJCategory *categoryItem = self.categoryList[indexPath.row]; cell.textLabel.text = categoryItem.name;
cell.imageView.image = [UIImage imageNamed:categoryItem.icon]; return cell;
} @end
最终效果:

美团HD(3)-加载分类导航数据的更多相关文章
- 【JAVAWEB学习笔记】网上商城实战2:异步加载分类、Redis缓存分类和显示商品
网上商城实战2 今日任务 完成分类模块的功能 完成商品模块的功能 1.1 分类模块的功能: 1.1.1 查询分类的功能: 1.1.2 查询分类的代码实现: 1.1.2.1 创建 ...
- ASP.NET MVC深入浅出(被替换) 第一节: 结合EF的本地缓存属性来介绍【EF增删改操作】的几种形式 第三节: EF调用普通SQL语句的两类封装(ExecuteSqlCommand和SqlQuery ) 第四节: EF调用存储过程的通用写法和DBFirst模式子类调用的特有写法 第六节: EF高级属性(二) 之延迟加载、立即加载、显示加载(含导航属性) 第十节: EF的三种追踪
ASP.NET MVC深入浅出(被替换) 一. 谈情怀-ASP.NET体系 从事.Net开发以来,最先接触的Web开发框架是Asp.Net WebForm,该框架高度封装,为了隐藏Http的无状态 ...
- [原创.数据可视化系列之三]使用Ol3加载大量点数据
不管是百度地图还是高德地图,都很难得见到在地图上加载大量点要素,比如同屏1000的,因为这样客户端性能会很低,尤其是IE系列的浏览器,简直是卡的要死.但有的时候,还真的需要,比如,我要加载全球的AQI ...
- jsTree 的简单用法--异步加载和刷新数据
首先这两个文件是必须要引用的,还有就是引用 jQuery 文件就不说了: <link href="/css/plugins/jsTree/style.min.css" rel ...
- 使用getJSON()方法异步加载JSON格式数据
使用getJSON()方法异步加载JSON格式数据 使用getJSON()方法可以通过Ajax异步请求的方式,获取服务器中的数组,并对获取的数据进行解析,显示在页面中,它的调用格式为: jQuery. ...
- 异步加载回来的数据不受JS控制了
写成下面这种方式时,异步加载回来的数据不受JS控制 $(."orderdiv").click(function(){ $(this).find(".orderinfo&q ...
- hive 压缩全解读(hive表存储格式以及外部表直接加载压缩格式数据);HADOOP存储数据压缩方案对比(LZO,gz,ORC)
数据做压缩和解压缩会增加CPU的开销,但可以最大程度的减少文件所需的磁盘空间和网络I/O的开销,所以最好对那些I/O密集型的作业使用数据压缩,cpu密集型,使用压缩反而会降低性能. 而hive中间结果 ...
- echarts 图表重新加载,原来的数据依然存在图表上
问题 在做一个全国地图上一些饼图,并且向省一级的地图钻取的时候,原来的饼图依然显示 原因 echars所有添加的图表都在一个series属性集合中,并且同一个echars对象默认是合并之前的数据的,所 ...
- mxnet自定义dataloader加载自己的数据
实际上关于pytorch加载自己的数据之前有写过一篇博客,但是最近接触了mxnet,发现关于这方面的教程很少 如果要加载自己定义的数据的话,看mxnet关于mnist基本上能够推测12 看pytorc ...
随机推荐
- Java 数组打印数组的 五种方法
Arrays.toString(arr) for(int n: arr) System.out.println(n+", "); for (int i = 0; i < ar ...
- Python学习笔记7-高级迭代器
将任何字符串作为python表达式求值: eval()方法: eval(source[, globals[, locals]]) -> value Evaluate the source in ...
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- 2-sql基本操作
sql基本操作 一.Sqlplus常用命令 1.查看oracle数据库的进程 2.查看oracle数据库运行状态 3.显示实例名(数据库名) 4.用sys账户登陆到数据库 5.解锁账户scott,并登 ...
- chpasswd命令
chpasswd命令是批量更新用户口令的工具,是把一个文件内容重新定向添加到/etc/shadow中. 语法 chpasswd(选项) 选项 -e:输入的密码是加密后的密文: -h:显示帮助信 ...
- overflow:hidden与margin:0 auto之间的冲突
相对于父容器水平居中的代码margin:0 auto与overflow:hidden之间存在冲突.当这两个属性同时应用在一个DIV上时,在chrome浏览器中将无法居中.至于为啥我也不明白.
- Linux下的C Socket编程 -- server端的简单示例
Linux下的C Socket编程(三) server端的简单示例 经过前面的client端的学习,我们已经知道了如何创建socket,所以接下来就是去绑定他到具体的一个端口上面去. 绑定socket ...
- Git开发分支管理
远程仓库有master和dev分支的情况 1. 克隆代码 git clone https://somewhere.com/master-dev.git 2. 查看所有分支 git branch --a ...
- python sokct 包详解
1. getaddrinfo简介getaddrinfo可解析得到IPv6地址,而gethostbyname仅能得到IPv4地址.getaddrinfo在Python的socket包中,以下为pytho ...
- 【swift学习笔记】六.访facebook登录页面
代码最下边有下载地址. 做这个demo的主要心得就是自适应所有的屏幕,要先布局大的框架,再一步一步设置小的细节. 看一下效果 再看一下自动适应所有屏幕的效果: keyboard打开时整个frame上移 ...