First, take a look at the effect of the map to achieve
Second, small analysis, you can first look at the back!
Third, the realization of tableview linkage is mainly divided into two situations
1, click on the left side of the cell to the right TableView roll to the corresponding position
2, sliding right tableview let left TableView roll to the corresponding position
1. First realize simple: Click on the left cell to let the right TableView roll to the corresponding position
MARK:-click on the cell's proxy method
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {
//judge whether the left TableView
if (TableView = = Self.lefttableview) {//
calculates the position where the right TableView will scroll (
N) Sindexpath *movetoindexpath = [Nsindexpath indexpathforrow:0 inSection:indexPath.row];
Move the right tableview to the specified location
[self.righttableview selectrowatindexpath:movetoindexpath animated:yes scrollPosition: Uitableviewscrollpositiontop];
Uncheck effect
[Self.righttableview deselectrowatindexpath:movetoindexpath animated:yes];
}
The left button clicks the linkage to fix!
2. Slide right TableView let left TableView roll to corresponding position
[self.rightTableView indexPathsForVisibleRows]
Returns the Indexpath of all the cell displayed in the interface
MARK:-One way to get a handle on the right side of the slide is the linkage to the left
-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {
//If the TableView on the left side Direct return
if (ScrollView = = Self.lefttableview) return;
Remove the Indexpath nsindexpath *topheaderviewindexpath of the cell that appears in the view and the top of it
= [[Self.righttableview Indexpathsforvisibler OWS] Firstobject];
The location where the left Talbelview moved to Indexpath
nsindexpath *movetoindexpath = [Nsindexpath indexpathforrow: Topheaderviewindexpath.section insection:0];
Move the left TableView to the specified Indexpath center display
[Self.lefttableview selectrowatindexpath:movetoindexpath Animated:yes Scrollposition:uitableviewscrollpositionmiddle];
}
The second step right side sliding with the left side of the linkage to fix! That's the simple thing to do!!!
Four, warning
See people judging by these two methods!!! Do NOT use!!!
can cause TableView to be inaccurate.
#pragma mark-uitableviewdelegate Proxy Method-
(void) TableView: (UITableView *) TableView Willdisplayheaderview: (UIView * View forsection: (nsinteger) Section {////
Headerview will be displayed
//Both methods are inaccurate
}
-(void) TableView: ( UITableView *) TableView Didenddisplayingheaderview: (UIView *) View forsection: (nsinteger) Section {///
/ Headerview has shown
//Both methods are inaccurate
}
The following are all sample code
VIEWCONTROLLER.M//Left/right double tableview linkage////Created by cool on 16/8/20. COPYRIGHT©2016 year Akuapp.
All rights reserved. #import "ViewController.h" #define Lefttablewidth [uiscreen mainscreen].bounds.size.width * 0.3 #define Righttablewid th [uiscreen mainscreen].bounds.size.width * 0.7 #define SCREENWIDTH [uiscreen mainscreen].bounds.size.width #define SCR eenheight [UIScreen mainscreen].bounds.size.height #define Leftcellidentifier @ "Leftcellidentifier" #define Rightcellidentifier @ "Rightcellidentifier" @interface Viewcontroller () <uitableviewdatasource,
Uitableviewdelegate> @property (nonatomic, weak) UITableView *lefttableview;
@property (nonatomic, weak) UITableView *righttableview;
@end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];
[Self.view AddSubview:self.leftTableView];
[Self.view AddSubview:self.rightTableView]; #pragma mark-tableview Data Source Proxy Method-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (NSInteger) Section {if (TableView = = Self.lefttableview) return 40;
return 8;
}-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {if (TableView = = Self.lefttableview) return 1;
return 40; }-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath {UITableView
Cell *cell; Left view if (TableView = = Self.lefttableview) {cell = [TableView dequeuereusablecellwithidentifier:leftcellidentif
Ier Forindexpath:indexpath];
Cell.textLabel.text = [NSString stringwithformat:@ "%ld", Indexpath.row];
View on the right} else {cell = [TableView dequeuereusablecellwithidentifier:rightcellidentifier Forindexpath:indexpath];
Cell.textLabel.text = [NSString stringwithformat:@ "group%ld-%ld rows", Indexpath.section, Indexpath.row];
} return cell; }-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) Section {if (TableView = = SELF.R Ighttableview) return [nsstring stringwithformat:@ "group%ld",Section];
return nil; #pragma mark-uitableviewdelegate Proxy Method-//-(void) TableView: (UITableView *) TableView Didenddisplayingheaderview: (UIV Iew * View forsection: (nsinteger) Section {////Both methods are inaccurate//}////-(void) TableView: (UITableView *) TableView Willdisplay Headerview: (UIView *) View forsection: (nsinteger) Section {/////Both methods are inaccurate//}//mark:-One method can handle the right side sliding with the left side of the linkage-(void) Scro Llviewdidscroll: (Uiscrollview *) ScrollView {//If left TableView direct return if (ScrollView = Self.lefttableview) return
; Remove the Indexpath nsindexpath *topheaderviewindexpath of the cell that appears in the view and the top of it = [[Self.righttableview indexpathsforvisiblerows]
Firstobject]; Left Talbelview mobile Indexpath nsindexpath *movetoindexpath = [Nsindexpath indexpathforrow:
Topheaderviewindexpath.section insection:0]; Move left TableView to specified Indexpath center [self.lefttableview Selectrowatindexpath:movetoindexpath Animated:yes ScrollPositi
On:uitableviewscrollpositionmiddle]; }//mark:-click on the cell's proxy method-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {//Select the left TableView if (TableView = SELF.L
Efttableview) {Nsindexpath *movetoindexpath = [Nsindexpath indexpathforrow:0 inSection:indexPath.row]; Move the right tableview to the specified location [Self.righttableview selectrowatindexpath:movetoindexpath animated:yes scrollPosition:
Uitableviewscrollpositiontop];
Uncheck effect [Self.righttableview Deselectrowatindexpath:movetoindexpath Animated:yes];
} #pragma mark-lazy load tableview-//Mark:-TableView on the left-(UITableView *) Lefttableview {if (!_lefttableview) {
UITableView *tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, Lefttablewidth, screenheight)];
[Self.view Addsubview:tableview];
_lefttableview = TableView;
Tableview.datasource = self;
Tableview.delegate = self;
[TableView Registerclass:[uitableviewcell class] forcellreuseidentifier:leftcellidentifier];
Tableview.backgroundcolor = [Uicolor Redcolor]; Tableview.tablefooterview = [[[UIView alloc] init];
return _lefttableview; //MARK:-Right TableView-(UITableView *) Righttableview {if (!_righttableview) {UITableView *tableview = [[Uita
Bleview Alloc] Initwithframe:cgrectmake (lefttablewidth, 0, Righttablewidth, screenheight)];
[Self.view Addsubview:tableview];
_righttableview = TableView;
Tableview.datasource = self;
Tableview.delegate = self;
[TableView Registerclass:[uitableviewcell class] forcellreuseidentifier:rightcellidentifier];
Tableview.backgroundcolor = [Uicolor Cyancolor];
Tableview.tablefooterview = [[UIView alloc] init];
return _righttableview; } @end
Vi. Summary
iOS to achieve about two tableview linkage effect of the content to this end, this effect in our usual time or quite common, interested friends can do their own hands-on, I hope that the study of everyone can help.