DJNavDropView.m

#import "DJNavDropView.h"
#import "DJCategory.h"
#import "DJNavMainCategoryCell.h"
#import "DJNavSubCategoryCell.h" @interface DJNavDropView()<UITableViewDataSource,UITableViewDelegate> /** 主分类 */
@property (weak, nonatomic) IBOutlet UITableView *mainTableView;
/** 子分类 */
@property (weak, nonatomic) IBOutlet UITableView *subTableView;
/** 选中的子类别集合 */
@property (nonatomic,strong) NSArray *selectedSubCategories; @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 { if (tableView == self.mainTableView) { // 主类别
return self.categoryList.count;
} else { // 子类别
return self.selectedSubCategories.count;
}
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.mainTableView) { // 主类别 DJNavMainCategoryCell *cell = [DJNavMainCategoryCell cellWithTableView:tableView];
// 设置当前Cell属性
DJCategory *categoryItem = self.categoryList[indexPath.row];
cell.textLabel.text = categoryItem.name;
cell.imageView.image = [UIImage imageNamed:categoryItem.icon];
// 如果当前主类别有子类别
if (categoryItem.subcategories.count) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 显示向右的箭头
} else {
cell.accessoryType = UITableViewCellAccessoryNone; // 隐藏箭头
}
return cell; } else { // 子类别 DJNavSubCategoryCell *cell = [DJNavSubCategoryCell cellWithTableView:tableView];
// 设置当前Cell属性
cell.textLabel.text = self.selectedSubCategories[indexPath.row];
return cell; }
} #pragma mark - TableView 代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == self.mainTableView) { // 点击主分类上面的条目
DJCategory *category = self.categoryList[indexPath.row];
self.selectedSubCategories = category.subcategories;
// 刷新子栏目列表数据
[self.subTableView reloadData];
} else { // 点击子分类上面的条目 } } @end

DJNavMainCategoryCell.m

#import "DJNavMainCategoryCell.h"

@implementation DJNavMainCategoryCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {

    static NSString *ID = @"main_category";
DJNavMainCategoryCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[DJNavMainCategoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
return cell;
} - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) { UIImageView *bg = [[UIImageView alloc] init];
bg.image = [UIImage imageNamed:@"bg_dropdown_leftpart"];
self.backgroundView = bg; UIImageView *selectedBg = [[UIImageView alloc] init];
selectedBg.image = [UIImage imageNamed:@"bg_dropdown_left_selected"];
self.selectedBackgroundView = selectedBg; }
return self;
} @end

最终效果:

美团HD(4)-二级联动效果的更多相关文章

  1. vue实现二级联动效果

    你如城市与省份间的二级联动效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...

  2. asp.net DropDownList实现二级联动效果

    1.在aspx页面中,拖入两个DroDownList控件,代码如下: <div>   <asp:DropDownList ID="s1" runat=" ...

  3. element ui select组件和table做分页完整功能和二级联动效果

    <template> <div class="index_box"> <div class="search_box"> &l ...

  4. asp.net DropDownList无刷新ajax二级联动实现详细过程

    只适合新手制作DropDownList无刷新ajax二级联动效果: 数据库实现,添加两表如图:表1,pingpai,表2,type,具体数据库实现看自己的理解: //页面主要代码: <asp:S ...

  5. Asp.Net下,基于Jquery的Ajax二级联动

    最近做一个项目,要求实现二级联动效果.背景为:通过学院的选择,联动出专业选项.起初想直接用微软的控件实现Ajax效果,但是DropDownList控件会自动触发PostBack,在后台根本就不好控制, ...

  6. js:二级联动示例

    联动原理 当用户点击省级的下拉选项,选择所在省,下一个下拉选项里的选项,则变成用户选择省下的所有市的信息,不会出现其它省市的信息. 省市数据 把省市数据,保存在js文件中,以json形式保存,以便读取 ...

  7. js小例子之二级联动

    联动原理 当用户点击省级的下拉选项,选择所在省,下一个下拉选项里的选项,则变成用户选择省下的所有市的信息,不会出现其它省市的信息. 省市数据 把省市数据,保存在js文件中,以json形式保存,以便读取 ...

  8. js实现菜单二级联动

    代码如下,以便自己以后方便查阅: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> < ...

  9. android中利用实现二级联动的效果

    按照惯例,首先上一张效果图. 本篇文章实现的效果就是如图中所圈的那样,实现类似于HTML中的二级联动的效果. 对于第一个选项我们读取的是本地xml文件来填充数据的, 对于第二个选项我们读取的是通过中央 ...

随机推荐

  1. 关于Spring的构造函数,init-method,和依赖注入的先后顺序

    接触学习Spring一段时间了,今天突然脑子短路,竟然一时间忘记了构造函数,init-method,和依赖注入的先后顺序,然后打开IDE去验证后.构造函数-->依赖注入-->init-me ...

  2. 通过中看不中用的代码分析Ioc容器,依赖注入....

    /** * 通过生产拥有超能力的超人实例 来理解IOC容器 */ //超能力模组接口 interface SuperModuleInterface{ public function activate( ...

  3. JavaScript 解析 Django Python 生成的 datetime 数据 时区问题解决

    JavaScript 解析 Django/Python 生成的 datetime 数据 当Web后台使用Django时,后台生成的时间数据类型就是Python类型的. 项目需要将几个时间存储到数据库中 ...

  4. 项目自动化建构工具gradle 入门5——在intellij中做一个gradle的web工程

    之前的几个小节,都是纯手工建文件夹,纯手工拷贝war包,或者纯手工解压个zip看看结果,,,,这还是我写了玩的helloWorld.若是玩大工程.几十个人的团队协同开发时,这么玩,,,,暴躁的程序员估 ...

  5. python学习5

    1.切片,python中一个比较重要的概念,其实和MATLAB中的数组的操作很相像. 比如对于 a =[1,2,3,4,...,100]如果想取前三个,即[1,2,3] 直接说a[0,3]即可,还可以 ...

  6. asp.net中缓存的使用介绍一

    asp.net中缓存的使用介绍一 介绍: 在我解释cache管理机制时,首先让我阐明下一个观念:IE下面的数据管理.每个人都会用不同的方法去解决如何在IE在管理数据.有的会提到用状态管理,有的提到的c ...

  7. [LeetCode] Valid Word Square 验证单词平方

    Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a v ...

  8. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  9. 微信随机红包(Java)

    概述 最近受一朋友提醒,问微信红包怎么实现的,当时思考了一下,觉得好像很容易,可是当真正实现的时候,发现其中有不少问题,于是小白博主查阅资料,其中资料主要来源于知乎的一篇讨论<微信红包的随机算法 ...

  10. [转]使用Enumeration和Iterator遍历集合类

    原文地址:http://www.cnblogs.com/xwdreamer/archive/2012/05/30/2526268.html 前言 在数据库连接池分析的代码实例中,看到其中使用Enume ...