美团HD(4)-二级联动效果
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)-二级联动效果的更多相关文章
- vue实现二级联动效果
你如城市与省份间的二级联动效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- asp.net DropDownList实现二级联动效果
1.在aspx页面中,拖入两个DroDownList控件,代码如下: <div> <asp:DropDownList ID="s1" runat=" ...
- element ui select组件和table做分页完整功能和二级联动效果
<template> <div class="index_box"> <div class="search_box"> &l ...
- asp.net DropDownList无刷新ajax二级联动实现详细过程
只适合新手制作DropDownList无刷新ajax二级联动效果: 数据库实现,添加两表如图:表1,pingpai,表2,type,具体数据库实现看自己的理解: //页面主要代码: <asp:S ...
- Asp.Net下,基于Jquery的Ajax二级联动
最近做一个项目,要求实现二级联动效果.背景为:通过学院的选择,联动出专业选项.起初想直接用微软的控件实现Ajax效果,但是DropDownList控件会自动触发PostBack,在后台根本就不好控制, ...
- js:二级联动示例
联动原理 当用户点击省级的下拉选项,选择所在省,下一个下拉选项里的选项,则变成用户选择省下的所有市的信息,不会出现其它省市的信息. 省市数据 把省市数据,保存在js文件中,以json形式保存,以便读取 ...
- js小例子之二级联动
联动原理 当用户点击省级的下拉选项,选择所在省,下一个下拉选项里的选项,则变成用户选择省下的所有市的信息,不会出现其它省市的信息. 省市数据 把省市数据,保存在js文件中,以json形式保存,以便读取 ...
- js实现菜单二级联动
代码如下,以便自己以后方便查阅: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> < ...
- android中利用实现二级联动的效果
按照惯例,首先上一张效果图. 本篇文章实现的效果就是如图中所圈的那样,实现类似于HTML中的二级联动的效果. 对于第一个选项我们读取的是本地xml文件来填充数据的, 对于第二个选项我们读取的是通过中央 ...
随机推荐
- error LNK2001: 无法解析的外部符号
1.错误描述 error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl PadSystem::Private::printQS ...
- bitmap解码
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BYTE unsigned c ...
- 解决 node-gyp rebuild 卡住 的问题
node-gyp在编译前会首先尝试下载node的headers文件,像这样: gyp http GET https://nodejs.org/download/release/v6.8.1/node- ...
- 单例模式中用volatile和synchronized来满足双重检查锁机制
背景:我们在实现单例模式的时候往往会忽略掉多线程的情况,就是写的代码在单线程的情况下是没问题的,但是一碰到多个线程的时候,由于代码没写好,就会引发很多问题,而且这些问题都是很隐蔽和很难排查的. 例子1 ...
- 45分钟带你入门Linux(附:笔者在工作室开讨论班录制的视频讲解)
第一部分 熟悉Linux基本操作 一.初识Linux 1.Linux特点 ◊ 开放性 ◊ 多用户 ◊ 多任务 ◊ 良好的用户界面 ◊ 设备独立性 ◊ 丰富的网络功能 ◊ 可靠的系统 ...
- 自己写的一个Pager分页组件,WebForm,Mvc都适用
我一说写这个功能的时候,好多人估计有疑问.分页功能网上多的是,搜一个不就行了,你这样不是浪费时间么.你说这句话的时候,我是比较信的,首先自己写一些东西是很耗时,有这些时间又能多打几盘LOL了.但是我觉 ...
- 【MySQL】mysql 1449 : The user specified as a definer ('root'@'%') does not exist
权限问题,授权 给 root 所有sql 权限 1.mysql> grant all privileges on *.* to root@"%" identified by ...
- ASP.NET-DataList控件-DataList嵌套
DataList是ASP.NET的数据控件之一,在使用时要对其进行数据绑定.但是使用过程中难免会出现需要根据已绑定表中的某列数据来作进一步的查询和显示,就需要使用DataList嵌套来解决此类问题. ...
- Djago模板拾起
在view中使用template: 首先在settings.py中配置模板文件的路径. TEMPLATE_DIRS = ( '/home/django/mysite/templates', ) 1.变 ...
- sql 触发器删除操作
create trigger CheckDelete on 表 for delete as ) select @state=isnull(字段,'') from deleted if (@state& ...