zoukankan      html  css  js  c++  java
  • 美团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(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

    最终效果:

  • 相关阅读:
    linux下启动和关闭网卡命令及DHCP上网
    python 编码问题
    paddlepaddle
    Convolutional Neural Network Architectures for Matching Natural Language Sentences
    deep learning RNN
    Learning Structured Representation for Text Classification via Reinforcement Learning 学习笔记
    Python IO密集型任务、计算密集型任务,以及多线程、多进程
    EM 算法最好的解释
    tensorflow 调参过程
    tensorflow 学习纪录(持续更新)
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6250405.html
Copyright © 2011-2022 走看看