IOS implementation expands level two list effect _ios

Source: Internet
Author: User

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.

Related Article

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.