djnavdropview.m
#import "DJNavDropView.h"#import "DJCategory.h"#import "DJNavMainCategoryCell.h"#import "DJNavSubCategoryCell.h"@interfaceDjnavdropview () <UITableViewDataSource,UITableViewDelegate>/** Main category*/@property (Weak, nonatomic) Iboutlet UITableView*Maintableview;/** Sub-category*/@property (Weak, nonatomic) Iboutlet UITableView*Subtableview;/** Selected sub-categories collection*/@property (nonatomic,strong) Nsarray*selectedsubcategories;@end@implementationDjnavdropview+(instancetype) DropView {return[[[NSBundle Mainbundle] loadnibnamed:@"Djnavdropview"Owner:nil Options:nil] lastobject];}- (void) Setcategorylist: (Nsarray *) categorylist {_categorylist=categorylist; //Refresh Data[Self.maintableview reloaddata];}#pragmaMark-tableview Data Source Method-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {if(TableView = = Self.maintableview) {//main category returnSelf.categoryList.count; } Else{//Sub-category returnSelf.selectedSubCategories.count; }}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {if(TableView = = Self.maintableview) {//main categoryDjnavmaincategorycell*cell =[Djnavmaincategorycell Cellwithtableview:tableview]; //set the current cell propertyDjcategory *categoryitem =Self.categorylist[indexpath.row]; Cell.textLabel.text=Categoryitem.name; Cell.imageView.image=[UIImage ImageNamed:categoryItem.icon]; //if the current main category has subcategories if(categoryItem.subcategories.count) { cell.accessorytype =Uitableviewcellaccessorydisclosureindicator;//Show Right ARROW}Else{Cell.accessorytype= Uitableviewcellaccessorynone;//Hide Arrows } returncell; } Else{//Sub-categoryDjnavsubcategorycell*cell =[Djnavsubcategorycell Cellwithtableview:tableview]; //set the current cell propertyCell.textLabel.text =Self.selectedsubcategories[indexpath.row]; returncell; }}#pragmaMark-tableview Proxy Method-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {if(TableView = = Self.maintableview) {//Click on the entry above the main categoryDjcategory *category =Self.categorylist[indexpath.row]; Self.selectedsubcategories=category.subcategories; //Refresh Sub-column list data[Self.subtableview Reloaddata]; } Else{//Click on the sub-category above entry }}@end
djnavmaincategorycell.m
#import "DJNavMainCategoryCell.h"@implementationDjnavmaincategorycell+ (Instancetype) Cellwithtableview: (UITableView *) TableView {StaticNSString *id =@"main_category"; Djnavmaincategorycell*cell =[TableView Dequeuereusablecellwithidentifier:id]; if(!cell) {Cell=[[Djnavmaincategorycell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; } returncell;}-(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; } returnSelf ;}@end
Final effect:
US group HD (4)-two-level linkage effect