亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

IOS實現左右兩個TableView聯動效果

2020-07-26 03:15:55
字體:
來源:轉載
供稿:網友

一、先來看看要實現的效果圖

二、小解析,可以先看看后面的!


三、實現 tableView聯動 主要分兩種狀況

     1、點擊 左側 cell 讓右側 tableView 滾到對應位置

     2、滑動 右側 tableView 讓左側 tableView 滾到對應位置

1.先實現簡單的:點擊 左側 cell 讓右側 tableView 滾到對應位置

//MARK: - 點擊 cell 的代理方法- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 判斷是否為 左側 的 tableView if (tableView == self.leftTableView) {  // 計算出 右側 tableView 將要 滾動的 位置  NSIndexPath *moveToIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row];  // 將右側 tableView 移動到指定位置  [self.rightTableView selectRowAtIndexPath:moveToIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];  // 取消選中效果  [self.rightTableView deselectRowAtIndexPath:moveToIndexPath animated:YES]; }}

左側 按鈕點擊的聯動 搞定!

2.滑動 右側 tableView 讓左側 tableView 滾到對應位置

[self.rightTableView indexPathsForVisibleRows] 返回 所有顯示在界面的 cell 的 indexPath

//MARK: - 一個方法就能搞定 右邊滑動時跟左邊的聯動- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // 如果是 左側的 tableView 直接return if (scrollView == self.leftTableView) return; // 取出顯示在 視圖 且最靠上 的 cell 的 indexPath NSIndexPath *topHeaderViewIndexpath = [[self.rightTableView indexPathsForVisibleRows] firstObject]; // 左側 talbelView 移動到的位置 indexPath NSIndexPath *moveToIndexpath = [NSIndexPath indexPathForRow:topHeaderViewIndexpath.section inSection:0]; // 移動 左側 tableView 到 指定 indexPath 居中顯示 [self.leftTableView selectRowAtIndexPath:moveToIndexpath animated:YES scrollPosition:UITableViewScrollPositionMiddle];}

第二步 右側 滑動 跟左側 的聯動 搞定! 對的 就是這么簡單!!!

四、警告

看到別人通過這兩個方法判斷!!! 勿用!!!

會導致 tableView 的聯動 不準確

#pragma mark - UITableViewDelegate 代理方法 -- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {//// headerView 將要顯示// 這兩個方法都不準確}- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section {//// headerView 已經顯示// 這兩個方法都不準確}

五、以下是所有示例代碼

//// ViewController.m// 左右雙tableView聯動//// Created by 阿酷 on 16/8/20.// Copyright © 2016年 AkuApp. All rights reserved.//#import "ViewController.h"#define leftTableWidth [UIScreen mainScreen].bounds.size.width * 0.3#define rightTableWidth [UIScreen mainScreen].bounds.size.width * 0.7#define ScreenWidth  [UIScreen mainScreen].bounds.size.width#define ScreenHeight [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 數據源代理方法 -- (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 { UITableViewCell *cell; // 左邊的 view if (tableView == self.leftTableView) {  cell = [tableView dequeueReusableCellWithIdentifier:leftCellIdentifier forIndexPath:indexPath];  cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row];  // 右邊的 view } else {  cell = [tableView dequeueReusableCellWithIdentifier:rightCellIdentifier forIndexPath:indexPath];  cell.textLabel.text = [NSString stringWithFormat:@"第%ld組-第%ld行", indexPath.section, indexPath.row]; } return cell;}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (tableView == self.rightTableView) return [NSString stringWithFormat:@"第 %ld 組", section]; return nil;}#pragma mark - UITableViewDelegate 代理方法 -//- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section {//// 這兩個方法都不準確//}////- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {//// 這兩個方法都不準確//}//MARK: - 一個方法就能搞定 右邊滑動時跟左邊的聯動- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // 如果是 左側的 tableView 直接return if (scrollView == self.leftTableView) return; // 取出顯示在 視圖 且最靠上 的 cell 的 indexPath NSIndexPath *topHeaderViewIndexpath = [[self.rightTableView indexPathsForVisibleRows] firstObject]; // 左側 talbelView 移動的 indexPath NSIndexPath *moveToIndexpath = [NSIndexPath indexPathForRow:topHeaderViewIndexpath.section inSection:0]; // 移動 左側 tableView 到 指定 indexPath 居中顯示 [self.leftTableView selectRowAtIndexPath:moveToIndexpath animated:YES scrollPosition:UITableViewScrollPositionMiddle];}//MARK: - 點擊 cell 的代理方法- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 選中 左側 的 tableView if (tableView == self.leftTableView) {  NSIndexPath *moveToIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row];  // 將右側 tableView 移動到指定位置  [self.rightTableView selectRowAtIndexPath:moveToIndexPath animated:YES scrollPosition:UITableViewScrollPositionTop];  // 取消選中效果  [self.rightTableView deselectRowAtIndexPath:moveToIndexPath animated:YES]; }}#pragma mark - 懶加載 tableView -// MARK: - 左邊的 tableView- (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: - 右邊的 tableView- (UITableView *)rightTableView { if (!_rightTableView) {  UITableView *tableView = [[UITableView 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

六、總結

IOS實現左右兩個TableView聯動效果的內容到這就結束了,這種的效果在我們平常的時候還是挺常見的,感興趣的朋友們可以自己動手操作起來,希望對大家的學習工作能有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
美女性感视频久久久| 欧美精品福利在线| 国产午夜精品理论片a级探花| www.亚洲天堂| 午夜精品一区二区三区在线视| 久久久久久噜噜噜久久久精品| 欧美在线影院在线视频| 亚洲一区二区三区乱码aⅴ蜜桃女| 日韩av黄色在线观看| 91国语精品自产拍在线观看性色| 日韩av在线网页| 欧美大片网站在线观看| 精品视频偷偷看在线观看| 亚洲视频一区二区| 97婷婷涩涩精品一区| 日韩av电影中文字幕| 亚洲第一综合天堂另类专| 日韩在线不卡视频| 亚洲国产精品99久久| 成人国产在线视频| 国产精品国产三级国产aⅴ浪潮| 欧美色图在线视频| 精品电影在线观看| 日韩麻豆第一页| 成人国产精品久久久久久亚洲| 九九精品在线播放| 国内精品久久久| 91高清视频免费观看| 国产精品jvid在线观看蜜臀| 欧美理论电影网| 在线播放国产一区二区三区| 中文一区二区视频| 日韩欧美中文第一页| 91国产视频在线| 国产成人久久久| 午夜精品一区二区三区视频免费看| 国产成人免费91av在线| 国产在线观看精品一区二区三区| 日韩欧美一区二区在线| 亚洲国产精品视频在线观看| 欧美激情高清视频| 久久国产精品久久国产精品| 欧美—级a级欧美特级ar全黄| 久久久999国产精品| 亚洲奶大毛多的老太婆| 91高潮精品免费porn| 成人中文字幕在线观看| 亚洲区一区二区| 亚洲成人久久一区| 日韩中文字幕第一页| 亚洲最新av在线网站| 欧美激情精品在线| 国产成人精品免高潮在线观看| 亚洲精品福利免费在线观看| 欧美日韩加勒比精品一区| 亚洲午夜性刺激影院| 久久精品国产电影| 91欧美精品成人综合在线观看| 国产z一区二区三区| 欧洲美女7788成人免费视频| 秋霞成人午夜鲁丝一区二区三区| 亚洲欧美色图片| 日韩欧美亚洲国产一区| 国产精品色视频| 8050国产精品久久久久久| 欧美国产日产韩国视频| 欧美一级淫片videoshd| 欧美有码在线观看视频| 日韩av电影国产| 欧美日韩国产区| 成人黄色免费片| 青草成人免费视频| 伊人一区二区三区久久精品| 亚洲视频在线观看| 日韩毛片在线观看| 色综合久久久888| 成人写真视频福利网| 日韩在线视频网站| 91美女片黄在线观看游戏| 岛国视频午夜一区免费在线观看| 国产精品免费在线免费| 成人精品福利视频| 国内偷自视频区视频综合| 日韩免费看的电影电视剧大全| 中文字幕v亚洲ⅴv天堂| 亚洲性av网站| 亚洲第一精品夜夜躁人人躁| 91情侣偷在线精品国产| 在线观看久久av| 亚洲第五色综合网| 成人激情免费在线| 国产精品美女无圣光视频| 91久久国产精品91久久性色| 精品欧美aⅴ在线网站| 欧美日韩福利视频| 久久精品这里热有精品| 亚洲国产欧美一区| 国产精品入口免费视| 91在线观看免费观看| 91中文在线视频| 国产精品欧美日韩久久| 成人网在线视频| 国产精品第三页| 久久久久久久一区二区| 日本一区二区在线播放| 亚洲国产精品资源| 久久久噜噜噜久噜久久| 国产91色在线免费| 国产一区二区三区在线观看网站| 欧美亚洲国产成人精品| 欧美性猛交xxxx免费看久久久| 亚洲免费电影在线观看| 91久久久久久久一区二区| 欧美成年人在线观看| 久久视频精品在线| 欧美激情中文字幕在线| 97久久精品人人澡人人爽缅北| 在线成人一区二区| 97超级碰碰碰| 亚洲免费av片| 77777少妇光屁股久久一区| 亚洲精品一区二区在线| 久久频这里精品99香蕉| 欧美日韩在线一区| 日韩在线视频免费观看高清中文| 91在线高清免费观看| 美女撒尿一区二区三区| 久久精品国产久精国产思思| 久久久噜噜噜久久中文字免| 国产成人鲁鲁免费视频a| 国产999精品| 欧美人与性动交a欧美精品| 一区二区福利视频| 精品久久久久久| 91精品国产91久久久久| 色偷偷888欧美精品久久久| 欧美性在线视频| 一区二区中文字幕| 国产日韩欧美黄色| 国产精品日韩在线| 欧美大人香蕉在线| 亚洲欧洲中文天堂| 91国产精品电影| 神马久久久久久| 大胆人体色综合| 欧美在线性视频| 欧美洲成人男女午夜视频| 亚洲美女动态图120秒| 8x海外华人永久免费日韩内陆视频| 欧美激情免费视频| 91国内精品久久| 国产精品影片在线观看| 国产美女扒开尿口久久久| 日韩有码在线观看| 成人国产精品日本在线| 欧美夜福利tv在线| 国产亚洲人成a一在线v站| 狠狠躁夜夜躁久久躁别揉| www.欧美精品| 亚洲石原莉奈一区二区在线观看| 国内久久久精品| 国产日韩欧美视频在线| 亚洲一区二区中文字幕| 欧美xxxx18国产|