American Group HD (4)-two-level linkage effect

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.