Let's take a look at the effect chart.
Usage (similar to UITableView)
Initialize Xdmulttableview
#import "XDMultTableView.h" ...
@property (nonatomic, ReadWrite, strong) Xdmulttableview *tableview;
_tableview = [[Xdmulttableview alloc] Initwithframe:cgrectmake (0, Self.view.frame.size.width, SELF.VIEW.FRAME.SIZE.HEIGHT-64)];
_tableview.opensectionarray = [Nsarray arraywithobjects:@1,@2, nil];
_tableview.delegate = self;
_tableview.datasource = self;
_tableview.backgroundcolor = [Uicolor whitecolor];
[Self.view Addsubview:_tableview];
Implementing a data source
-(Nsinteger) Mtableview: (Xdmulttableview *) Mtableview numberofrowsinsection: (Nsinteger) section{return 5;} -(Xdmulttableviewcell *) Mtableview: (Xdmulttableview *) Mtableview Cellforrowatindexpath: (NSIndexPath *) indexPath{St
atic nsstring *cellidentifier = @ "Cell";
UITableViewCell *cell = [Mtableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidenti
Fier];
} UIView *view = [[UIView alloc] initWithFrame:cell.bounds]; View.layer.backgroundColor = [Uicolor Whitecolor].
Cgcolor;
View.layer.masksToBounds = YES;
View.layer.borderWidth = 0.3; View.layer.borderColor = [Uicolor Lightgraycolor].
Cgcolor;
Cell.backgroundview = view;
Cell.selectionstyle = Uitableviewcellselectionstylenone;
return cell;
}-(Nsinteger) Numberofsectionsintableview: (Xdmulttableview *) mtableview{return 6;} -(NSString *) Mtableview: (Xdmulttableview *) Mtableview TitleforheadeRinsection: (Nsinteger) section{return @ "I am the head";}
Implementing a Proxy
-(CGFloat) Mtableview: (Xdmulttableview *) Mtableview Heightforrowatindexpath: (Nsindexpath *) indexPath{return
50 ;
}
-(CGFloat) Mtableview: (Xdmulttableview *) Mtableview heightforheaderinsection: (nsinteger) section{return
;
}
-(void) Mtableview: (Xdmulttableview *) Mtableview willopenheaderatsection: (nsinteger) section{NSLog
(@ " will be expanded ");
}
-(void) Mtableview: (Xdmulttableview *) Mtableview willcloseheaderatsection: (nsinteger) section{NSLog
(@ "About to close") ;
}
-(void) Mtableview: (Xdmulttableview *) Mtableview Didselectrowatindexpath: (Nsindexpath *) indexpath{NSLog
(@ " Click cell ");
The implementation principle of the list expansion shutdown
register a gesture in the section header
Section header view setting tag value to section
view.tag = section;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Tapheader:)];
[View Addgesturerecognizer:tap];
Response Events for gestures
-(void) Tapheader: (UITapGestureRecognizer *) Tap {Nsinteger section = Tap.view.tag;
NSNumber *sectionobj = [NSNumber numberwithinteger:section];
Uiimageview *imageview = (Uiimageview *) [Tap.view viewwithtag:100]; _multopensectionarray is used to record the expansion and shutdown status of each section if ([_multopensectionarray containsobject:sectionobj]) {Nsarray *delet
Earray = [self builddeleterowwithsection:section];
[_multopensectionarray Removeobject:sectionobj]; All indexpath of the section that you want to close [_tableview deleterowsatindexpaths:deletearray withrowanimation:
Uitableviewrowanimationfade];
[UIView animatewithduration:0.3 animations:^{imageview.transform = cgaffinetransformmakerotation (-M_PI/2);
}];
}else{[_multopensectionarray addobject:sectionobj];
All Indexpath Nsarray *insertarray = [self buildinsertrowwithsection:section] of the section that you want to expand;
[_tableview Insertrowsatindexpaths:insertarray Withrowanimation:uitableviewrowanimationfade]; [UIView animatewithduration:0.3 animations:^{IMAGEVIEW.TRANSFORM = cgaffinetransformmakerotation (0);
}]; }
}
Summarize
This is the iOS implementation of the two-level list of the full content of the results, I hope that you learn to develop iOS can help.