The swipe menu is a very popular iOS control
First on:
This is developed using GitHub's jtreveal framework, and links are https://github.com/agassiyzh/JTRevealSidebarDemo/commit/ ac03d9d7be4f1392020627e5fe8c22b972de4704
Our Viewcontroller to implement the two optional methods of protocol Jtrevealsidebarv2delegate
@optional-(UIView *) viewforleftsidebar;-(UIView *) Viewforrightsidebar;
-(UIView *) Viewforleftsidebar {CGRect mainFrame = [[UIScreen mainscreen] applicationframe]; UITableView *view = Self.leftsidebarview; if (! View) {view = Self.leftsidebarview = [[UITableView alloc] Initwithframe:cgrectmake (0, Mainframe.ori GIN.Y, MainFrame.size.height) Style:uitableviewstyleplain]; View.datasource = self; View.delegate = self; View.autoresizingmask = Uiviewautoresizingflexibleleftmargin | Uiviewautoresizingflexibleheight; View.backgroundcolor = [Uicolor Whitecolor]; uiview* Rightheaderview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 250, 42)]; Rightheaderview.backgroundcolor = [Uicolor Whitecolor]; Rightheaderview.opaque = NO; uilabel* lable = [[UILabel alloc] Initwithframe:cgrectmake (90, 2, 100, 38)]; [Lable settext:@ "left View"]; uifont* font = [Uifont systemfontofsize:20]; Lable.font = font; [Rightheaderview Addsubview:laBLE]; uiview* lines = [[UIView alloc] Initwithframe:cgrectmake (0, 42, 300, 2)]; Lines.backgroundcolor = [Uicolor Lightgraycolor]; [Rightheaderview Addsubview:lines]; uibutton* button = [[UIButton alloc] Initwithframe:cgrectmake (213, 2, 53, 38)]; [Button settitle:@ "Edit" forstate:uicontrolstatenormal]; [Button Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (leftbuttonclicked:) forcontrolevents:uicontroleventtouchupinside]; [Rightheaderview Addsubview:button]; View.tableheaderview = Rightheaderview; } return view;}
Initialize title first in Viewcontroller
-(void) addtiltebar{uibarbuttonitem *back = [[Uibarbuttonitem alloc] initwithtitle:@ "left" Style:uibarbuttonitemstylepl Ain target:self Action: @selector (Showleftsidebar:)]; Self.navigationItem.leftBarButtonItem = back; [Back release]; nsarray* array = [[Nsarray alloc] initwithobjects:@ ' left tab ', @ ' right tab ', nil]; uisegmentedcontrol* segment = [[Uisegmentedcontrol alloc] initwithitems:array]; CGRect rect = CGRectMake (80.0f, 8.0f, 170.0f, 30.0f); Segment.frame = rect; Segment.segmentedcontrolstyle = Uisegmentedcontrolstylebar; Segment.selectedsegmentindex =-1; [Segment Addtarget:self Action: @selector (segmentaction:) forcontrolevents:uicontroleventvaluechanged]; Self.navigationItem.titleView = segment; [Segment release]; Uibarbuttonitem *mapbutton = [[Uibarbuttonitem alloc] initwithtitle:@ "right" Style:uibarbuttonitemstylebordered target:selfAction: @selector (Revealrightsidebar:)]; [Button2 addtarget:self Action: @selector (Revealrightsidebar:) forcontrolevents:uicontroleventtouchupinside]; Self.navigationItem.rightBarButtonItem = Mapbutton; Self.navigationItem.revealSidebarDelegate = self; [Mapbutton release];
Click on the left side of the event is
-(void) Showleftsidebar: (ID) Sender { jtrevealedstate state = Jtrevealedstateleft; if (self.navigationController.revealedState = = jtrevealedstateleft) {state = Jtrevealedstateno; } [Self.navigationcontroller setrevealedstate:state];}
These TableView delegate and DataSource in the interface share a
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{if (TableView = = Self.rightsidebarview) {return [Rightarray count]; }else if (TableView = = Self.leftsidebarview) {return [Leftarray count]; }else{return [names Count]; }}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{if ( TableView = = Self.rightsidebarview) {static NSString *cellidentifier = @ "Rightcell"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:c Ellidentifier] autorelease]; }//Configure the cell ... Nsuinteger row = [Indexpath row]; Nsuinteger section = [Indexpath section]; Cell.textLabel.textAlignment = Uitextalignmentcenter; Cell.textLabel.textAlignment = Nstextalignmentcenter; Cell.textLabel.text = [Rightarray objectatindex:row]; return cell; } else if (TableView = = Self.leftsidebarview) {static NSString *cellidentifier = @ "Left_cell"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:c Ellidentifier] autorelease]; }//Configure the cell ... Nsuinteger row = [Indexpath row]; Nsuinteger section = [Indexpath section]; Cell.textLabel.textAlignment = Uitextalignmentcenter; Cell.textLabel.textAlignment = Nstextalignmentcenter; Cell.textLabel.text = [Leftarray objectatindex:row]; return cell; }else {static NSString *tablesampleidentifier = @ "Tablesampleidentifier"; UITableViewCell *cell = [[[UITableViewCell alloc] Initwithframe:cgrectzero ReuseidEntifier:nil] autorelease]; UITableViewCell *cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseIdentifier: Tablesampleidentifier]; Cell.textLabel.text = [names ObjectAtIndex:indexPath.row]; return cell; }}
Code can be downloaded in http://download.csdn.net/detail/baidu_nod/7541417