1.點擊左側(cè)cell,讓右邊tableview滾動到相應(yīng)位置
2.滑動右側(cè)tableview,讓左側(cè)tableview選中相應(yīng)cell
寫過好幾次了,稍微理解一下,其實簡單的
效果
Untitled.gif
創(chuàng)建兩個tableview
@property (nonatomic , weak) UITableView *leftTableView;
@property (nonatomic , weak) UITableView *rightTableView;
loadTableView
UITableView *ltableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, HHBWIDTH * 0.3, HHBHEIGHT-64-40)];
_leftTableView = ltableView;
_leftTableView.delegate = self;
_leftTableView.dataSource = self;
_leftTableView.backgroundColor = [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
_leftTableView.sectionHeaderHeight = 38;
_leftTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
_leftTableView.separatorStyle = UITableViewScrollPositionNone;
[self.view addSubview:_leftTableView];
UITableView *rtableView = [[UITableView alloc] initWithFrame:CGRectMake(HHBWIDTH * 0.3, 0, HHBWIDTH * 0.7, HHBHEIGHT-64-40)];
_rightTableView = rtableView;
_rightTableView.delegate = self;
_rightTableView.dataSource = self;
_rightTableView.backgroundColor = SELFBGColor;
_rightTableView.sectionHeaderHeight = 38;
_rightTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
[self.view addSubview:_rightTableView];
常規(guī)代碼片
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (tableView == _rightTableView) {
return _rightdataSoure.count;
}else{
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == _leftTableView) {
return _leftdataSoure.count;
}else{
return [[_rightdataSoure[section] objectForKey:@"title"] count];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView == _leftTableView) {
return 43;
}
return 30+48*[HuPageConfig plus_MagnifyingPower];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _leftTableView) {
static NSString *cellID = @"cellID";
inHospitalLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell) {
cell = [[inHospitalLeftTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.title.text = @"心血管內(nèi)科";
return cell;
}else{
static NSString *cellID = @"cellID";
inHospitalRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (nil == cell) {
cell = [[inHospitalRightTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
點擊左側(cè)Cell效果
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _leftTableView) {
NSIndexPath *moveIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row];
//animated為YES會導(dǎo)致leftTableView選擇亂跳
[_rightTableView selectRowAtIndexPath:moveIndexPath animated:NO scrollPosition:UITableViewScrollPositionTop];
[_rightTableView deselectRowAtIndexPath:moveIndexPath animated:YES];
}else {
}
}
滑動右側(cè)tableview 效果
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.leftTableView) {
return;
}
NSIndexPath *topIndexPath = [[_rightTableView indexPathsForVisibleRows]firstObject];
NSIndexPath *moveIndexPath = [NSIndexPath indexPathForRow:topIndexPath.section inSection:0];
[_leftTableView selectRowAtIndexPath:moveIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
小白總結(jié),歡迎打臉指正