美团HD(3)-加载分类导航数据
2017-01-04 22:08
323 查看
DJHomeViewController.m
DJNavDropView.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(300, 360); // 设置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
最终效果:
相关文章推荐
- 【基础】Equal方法、面向对象-多态-继承-封装
- C#实现高精度定时器
- openstack源码分析(一)------------如何入手
- 使用基于注解的mybatis时,利用反射和注解生成sql语句
- 利用python 实现简单 爬虫
- 各种java工具包目录
- centos7安装并配置mysql
- 个人记录-LeetCode 68. Text Justification
- win10系统 CAJ文件打不开 老弹出 File doesn't existed or can't be visited normally! 文件不存在或不能正常访问
- String中的equals和==
- 锁Lock 那点事儿
- 成绩排序(关键字排序)
- Mac 安装mysql遇到的坑
- Java内存模型——基础
- 集合框架_HashSet存储自定义对象并遍历练习
- vs studio2005 未知错误 0X8013134b 解决办法 1 例
- 在Spring MVC中使用Apache Shiro安全框架
- 递归判断递增数组
- jQuery中的$(#id)和document.getelementbyid(id)的不同
- 为什么java没有多继承