多个UITableView横向切换的简单实现(有点类似网易新闻)
实现多列表切换,位置监控,置顶等功能。
方法一:
创建一个TableView,在切换的时候请求各类目需要的数据,然后刷新列表,通过动画模拟出滑动效果。
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
- {
- //选择视图数组
- NSMutableArray *selectArray;
- //选择视图
- UIView *selectView;
- //列表
- UITableView *jiuJiuTableView;
- //选择类型
- NSInteger priceType;
- //切换之前的类型
- NSInteger oldType;
- //数量显示(返回顶部)
- UIView *countView;
- //记录tableview的contentOffset.y
- CGFloat lastY;
- //返回顶部
- UIButton *toTopButton;
- //记录tableview的位置
- NSMutableDictionary *jiLuDictionary;
- }
- //数据源
- @property (nonatomic, strong) NSMutableArray *tableArray;
- @end
- #import "ViewController.h"
- //tableview的cell的高度
- #define cellHeight self.view.frame.size.width*0.4
- @interface ViewController ()
- @end
- @implementation ViewController
- @synthesize tableArray;
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- //初始化数据源
- [self initTableArray];
- //初始化分类数据
- [self initSelectArray];
- //添加选择视图
- [self addSelectView];
- //添加滚动列表
- [self addTableView];
- }
- //初始化数据源
- - (void)initTableArray
- {
- //数据源
- if(self.tableArray == nil)
- {
- //初始化(实际使用时在此处请求类型1的数据即可)
- self.tableArray = [[NSMutableArray alloc] initWithObjects:@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1", nil];
- jiLuDictionary = [[NSMutableDictionary alloc] init];
- }
- }
- //初始化分类数据
- - (void)initSelectArray
- {
- priceType = ;
- oldType = ;
- if (selectArray == nil)
- {
- selectArray = [[NSMutableArray alloc] initWithObjects:@"类型1",@"类型2",@"类型3", nil];
- }
- }
- //添加选择视图
- - (void)addSelectView
- {
- selectView = [[UIView alloc] initWithFrame:CGRectMake(, , self.view.frame.size.width, )];
- [self.view addSubview:selectView];
- CGFloat buttonW = self.view.frame.size.width/selectArray.count;
- for (int i = ; i < selectArray.count; i++ )
- {
- UIButton *selectButton = [[UIButton alloc] initWithFrame:CGRectMake(buttonW*i, , buttonW, )];
- selectButton.tag = +i;
- [selectButton setTitle:selectArray[i] forState:UIControlStateNormal];
- [selectButton setTitleColor:[UIColor colorWithRed:69.0/255.0 green:69.0/255.0 blue:69.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- [selectButton addTarget:self action:@selector(clickedSelectButton:) forControlEvents:UIControlEventTouchUpInside];
- [selectView addSubview:selectButton];
- if (i != )
- {
- //分隔线
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(buttonW*i, (-)/, , )];
- lineImageView.backgroundColor = [UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0];
- [selectView addSubview:lineImageView];
- }
- else
- {
- [selectButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:83.0/255.0 blue:96.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- }
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, -, self.view.frame.size.width, )];
- lineImageView.backgroundColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
- [selectView addSubview:lineImageView];
- }
- //添加列表
- - (void)addTableView
- {
- if (jiuJiuTableView == nil)
- {
- jiuJiuTableView = [[UITableView alloc] initWithFrame:CGRectMake(, +, self.view.frame.size.width, self.view.frame.size.height--) style:UITableViewStylePlain];
- jiuJiuTableView.dataSource = self;
- jiuJiuTableView.delegate = self;
- //默认分隔线设置为无
- jiuJiuTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:jiuJiuTableView];
- //数量显示(返回顶部)
- countView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(jiuJiuTableView.frame)-, CGRectGetMaxY(jiuJiuTableView.frame)-, , )];
- countView.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:0.8];
- countView.layer.masksToBounds = YES;
- countView.layer.cornerRadius = ;
- [self.view addSubview:countView];
- UIImageView *lineView = [[UIImageView alloc] initWithFrame:CGRectMake((-)/, (-)/, , )];
- lineView.backgroundColor = [UIColor whiteColor];
- lineView.alpha = 0.8;
- [countView addSubview:lineView];
- UILabel *currentCount = [[UILabel alloc] initWithFrame:CGRectMake(lineView.frame.origin.x, lineView.frame.origin.y-, lineView.frame.size.width, )];
- currentCount.tag = ;
- currentCount.textAlignment = NSTextAlignmentCenter;
- currentCount.textColor = [UIColor whiteColor];
- currentCount.font = [UIFont systemFontOfSize:];
- [countView addSubview:currentCount];
- UILabel *totalCount = [[UILabel alloc] initWithFrame:CGRectMake(lineView.frame.origin.x, lineView.frame.origin.y+, lineView.frame.size.width, )];
- totalCount.tag = ;
- totalCount.textAlignment = NSTextAlignmentCenter;
- totalCount.textColor = [UIColor whiteColor];
- totalCount.font = [UIFont systemFontOfSize:];
- [countView addSubview:totalCount];
- countView.hidden = YES;
- //返回顶部
- toTopButton = [[UIButton alloc] initWithFrame:countView.frame];
- toTopButton.layer.masksToBounds = YES;
- toTopButton.layer.cornerRadius = ;
- [toTopButton setImage:[UIImage imageNamed:@"clickedToTop.png"] forState:UIControlStateNormal];
- toTopButton.alpha = 0.8;
- [toTopButton addTarget:self action:@selector(clickedToTop) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:toTopButton];
- toTopButton.hidden = YES;
- //添加滑动手势
- UISwipeGestureRecognizer *swipeGestureToRight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeToRight)];
- swipeGestureToRight.direction=UISwipeGestureRecognizerDirectionRight;
- [jiuJiuTableView addGestureRecognizer:swipeGestureToRight];
- UISwipeGestureRecognizer *swipeGestureToLeft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeToLeft)];
- swipeGestureToLeft.direction=UISwipeGestureRecognizerDirectionLeft;
- [jiuJiuTableView addGestureRecognizer:swipeGestureToLeft];
- }
- }
- #pragma mark ------------------点击事件----------------------
- //记录各类别tableview的位置
- - (void)writeJiLuDictionary
- {
- NSNumber *jiLuNum = [NSNumber numberWithFloat:jiuJiuTableView.contentOffset.y];
- if (priceType == )
- {
- [jiLuDictionary setObject:jiLuNum forKey:@"jiuJiuY"];
- }
- else if (priceType == )
- {
- [jiLuDictionary setObject:jiLuNum forKey:@"shiJiuY"];
- }
- else if (priceType == )
- {
- [jiLuDictionary setObject:jiLuNum forKey:@"erJiuY"];
- }
- }
- //点击选择按钮事件
- - (void)clickedSelectButton:(UIButton *)sender
- {
- UIButton *button = sender;
- [self writeJiLuDictionary];
- if (button.tag == )
- {
- priceType = ;
- }
- else if (button.tag == )
- {
- priceType = ;
- }
- else if (button.tag == )
- {
- priceType = ;
- }
- [self changeUIAndReloadData];
- }
- //左右滑动事件
- - (void)swipeToRight
- {
- [self writeJiLuDictionary];
- if (priceType == )
- {
- return;
- }
- else
- {
- priceType = priceType-;
- }
- [self changeUIAndReloadData];
- }
- - (void)swipeToLeft
- {
- [self writeJiLuDictionary];
- if (priceType == )
- {
- return;
- }
- else
- {
- priceType = priceType+;
- }
- [self changeUIAndReloadData];
- }
- //改变UI,刷新数据
- - (void)changeUIAndReloadData
- {
- NSInteger buttonTag = ;
- if (priceType == )
- {
- buttonTag = ;
- [jiuJiuTableView setContentOffset:CGPointMake(, [jiLuDictionary[@"jiuJiuY"] floatValue]) animated:NO];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1", nil]];
- }
- else if (priceType == )
- {
- buttonTag = ;
- [jiuJiuTableView setContentOffset:CGPointMake(, [jiLuDictionary[@"shiJiuY"] floatValue]) animated:NO];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2", nil]];
- }
- else if (priceType == )
- {
- buttonTag = ;
- [jiuJiuTableView setContentOffset:CGPointMake(, [jiLuDictionary[@"erJiuY"] floatValue]) animated:NO];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3", nil]];
- }
- for (int j = ; j < +selectArray.count; j++)
- {
- UIButton *selectButton = (UIButton *)[selectView viewWithTag:j];
- if (j == buttonTag)
- {
- [selectButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:83.0/255.0 blue:96.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- else
- {
- [selectButton setTitleColor:[UIColor colorWithRed:69.0/255.0 green:69.0/255.0 blue:69.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- }
- //添加动画
- CATransition *transition = [CATransition animation];
- transition.delegate = self;
- transition.duration = 0.5f;
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- transition.type = kCATransitionPush;
- if (oldType == priceType)
- {
- return;
- }
- else if (oldType < priceType)
- {
- transition.subtype = kCATransitionFromRight;
- }
- else
- {
- transition.subtype = kCATransitionFromLeft;
- }
- oldType = priceType;
- [jiuJiuTableView reloadData];
- [jiuJiuTableView.layer addAnimation:transition forKey:@"animation"];
- }
- //返回顶部事件
- - (void)clickedToTop
- {
- [jiuJiuTableView setContentOffset:CGPointMake(, ) animated:YES];
- }
- #pragma mark --------------tableviewDataSource---------------
- //每组的行数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.tableArray.count;
- }
- //设置行数据
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellString = @"cellString";//cell的重用
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellString];
- //设置点选效果为无
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.accessoryType = UITableViewCellAccessoryNone;
- }
- cell.textLabel.text = [NSString stringWithFormat:@"%@第%li行",self.tableArray[indexPath.row],(long)indexPath.row+];
- //更新数量
- UILabel *currentCount = (UILabel *)[countView viewWithTag:];
- UILabel *totalCount = (UILabel *)[countView viewWithTag:];
- currentCount.text = [NSString stringWithFormat:@"%li",(long)indexPath.row+];
- totalCount.text = [NSString stringWithFormat:@"%li",(long)self.tableArray.count];
- //分隔线
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, cellHeight-, self.view.frame.size.width-, )];
- [lineImageView setBackgroundColor:[UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1.0]];
- [cell addSubview:lineImageView];
- return cell;
- }
- #pragma mark ---------------tableviewDelegate------------------
- //设置行高
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return cellHeight;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"点击了第%ld行",indexPath.row+);
- }
- #pragma mark ----------------UIScrollViewDelegate-----------------
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (scrollView == jiuJiuTableView)
- {
- CGFloat y = scrollView.contentOffset.y;
- if (y < cellHeight*)
- {
- countView.hidden = YES;
- toTopButton.hidden = YES;
- }
- else
- {
- if (y > lastY)
- {
- countView.hidden = NO;
- toTopButton.hidden = YES;
- }
- else
- {
- countView.hidden = YES;
- toTopButton.hidden = NO;
- }
- }
- lastY = y;
- }
- }
- //请求最新数据成功
- -(void)requestJiuYuanNewFinish:(NSArray *)array
- {
- [self.tableArray removeAllObjects];
- [self.tableArray addObjectsFromArray:array];
- //刷新列表
- //[jiuJiuTableView reloadData];
- }
方法二:
创建多个TableView,放在ScrollView中,实现横向滑动。(相比性能等方面,推荐使用第一种方法)
- #import <UIKit/UIKit.h>
- @interface JiuKuaiJiuViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
- {
- //两列的collectionview
- UICollectionView *JFCollectionView;
- //选择视图数组
- NSArray *selectArray;
- //列表容器
- UIScrollView *containerScrollView;
- }
- //数据源
- @property(nonatomic, strong) NSMutableArray *tableArray;
- @end
- #import "JiuKuaiJiuViewController.h"
- //tableview的cell的高度
- #define cellHeight self.view.frame.size.width*0.4
- @interface JiuKuaiJiuViewController ()
- @end
- @implementation JiuKuaiJiuViewController
- @synthesize tableArray;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- //初始化数据源
- [self initTableArray];
- //初始化分类数据
- [self initSelectArray];
- //添加选择视图
- [self addSelectView];
- //添加滚动列表
- [self addTableView];
- }
- //初始化数据源
- - (void)initTableArray
- {
- if (self.tableArray == nil)
- {
- self.tableArray = [[NSMutableArray alloc] initWithObjects:@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1", nil];
- }
- }
- //初始化分类数据
- - (void)initSelectArray
- {
- if (selectArray == nil)
- {
- selectArray = [[NSArray alloc] initWithObjects:@"类型1",@"类型2",@"类型3", nil];
- }
- }
- //添加选择视图
- - (void)addSelectView
- {
- CGFloat buttonW = self.view.frame.size.width/selectArray.count;
- for (int i = ; i < selectArray.count; i++ )
- {
- UIButton *selectButton = [[UIButton alloc] initWithFrame:CGRectMake(buttonW*i, , buttonW, )];
- selectButton.tag = +i;
- [selectButton setTitle:selectArray[i] forState:UIControlStateNormal];
- [selectButton setTitleColor:[UIColor colorWithRed:69.0/255.0 green:69.0/255.0 blue:69.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- [selectButton addTarget:self action:@selector(clickedSelectButton:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:selectButton];
- if (i != )
- {
- //分隔线
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(buttonW*i, +(-)/, , )];
- lineImageView.backgroundColor = [UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0];
- [self.view addSubview:lineImageView];
- }
- else
- {
- [selectButton setTitleColor:[UIColor colorWithRed:255.0/255.0 green:83.0/255.0 blue:96.0/255.0 alpha:1.0] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- }
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, +, self.view.frame.size.width, )];
- lineImageView.backgroundColor = [UIColor colorWithRed:222.0/255.0 green:222.0/255.0 blue:222.0/255.0 alpha:1.0];
- [self.view addSubview:lineImageView];
- }
- //添加列表
- - (void)addTableView
- {
- if (containerScrollView == nil)
- {
- containerScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(, ++, self.view.frame.size.width, self.view.frame.size.height---)];
- containerScrollView.delegate = self;
- containerScrollView.pagingEnabled = YES;
- containerScrollView.contentSize = CGSizeMake(self.view.frame.size.width * selectArray.count, containerScrollView.frame.size.height);
- [self.view addSubview:containerScrollView];
- for (int k = ; k < selectArray.count; k++)
- {
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(self.view.frame.size.width*k, , self.view.frame.size.width, containerScrollView.frame.size.height) style:UITableViewStylePlain];
- tableView.tag = +k;
- tableView.dataSource = self;
- tableView.delegate = self;
- //默认分隔线设置为无
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [containerScrollView addSubview:tableView];
- }
- }
- else
- {
- //刷新列表
- for (int i = ; i < +selectArray.count; i++)
- {
- UITableView *tableView = (UITableView *)[containerScrollView viewWithTag:i];
- [tableView reloadData];
- }
- }
- }
- //点击选择按钮事件
- - (void)clickedSelectButton:(UIButton *)sender
- {
- UIButton *button = sender;
- for (int j = ; j < +selectArray.count; j++)
- {
- UIButton *selectButton = (UIButton *)[self.view viewWithTag:j];
- if (j == button.tag)
- {
- [selectButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- else
- {
- [selectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- }
- if (button.tag == )
- {
- [containerScrollView setContentOffset:CGPointMake(, ) animated:YES];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1", nil]];
- }
- else if (button.tag == )
- {
- [containerScrollView setContentOffset:CGPointMake(self.view.frame.size.width, ) animated:YES];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2", nil]];
- }
- else if (button.tag == )
- {
- [containerScrollView setContentOffset:CGPointMake(self.view.frame.size.width*, ) animated:YES];
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3", nil]];
- }
- }
- #pragma mark --------------tableviewDataSource---------------
- //每组的行数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.tableArray.count;
- }
- //设置行数据
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *cellString = @"cellString";//cell的重用
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellString];
- //设置点选效果为无
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.accessoryType = UITableViewCellAccessoryNone;
- }
- cell.textLabel.text = [NSString stringWithFormat:@"%@第%li行",self.tableArray[indexPath.row],(long)indexPath.row+];
- //分隔线
- UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, cellHeight-, self.view.frame.size.width-, )];
- [lineImageView setBackgroundColor:[UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1.0]];
- [cell addSubview:lineImageView];
- return cell;
- }
- #pragma mark ---------------tableviewDelegate------------------
- //设置行高
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return cellHeight;
- }
- #pragma mark ----------------scrollViewDelegate----------------
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- if (scrollView == containerScrollView)
- {
- CGPoint point = scrollView.contentOffset;
- NSInteger selectIndex = ;
- if (point.x == )
- {
- selectIndex = ;
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1",@"类型1", nil]];
- }
- else if (point.x == self.view.frame.size.width)
- {
- selectIndex = ;
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2",@"类型2", nil]];
- }
- else if (point.x == self.view.frame.size.width*)
- {
- selectIndex = ;
- //实际使用时将此处换成请求语句,在请求成功的方法中得到请求数据之后更新数组,刷新列表即可。例如在方法“requestJiuYuanNewFinish”中。
- [self requestJiuYuanNewFinish:[NSArray arrayWithObjects:@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3",@"类型3", nil]];
- }
- for (int j = ; j < +selectArray.count; j++)
- {
- UIButton *selectButton = (UIButton *)[self.view viewWithTag:j];
- if (j == selectIndex)
- {
- [selectButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- else
- {
- [selectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [selectButton.titleLabel setFont:[UIFont systemFontOfSize:]];
- }
- }
- }
- }
- //请求最新数据成功
- -(void)requestJiuYuanNewFinish:(NSArray *)array
- {
- [self.tableArray removeAllObjects];
- [self.tableArray addObjectsFromArray:array];
- //刷新滚动列表
- [self addTableView];
- }
- @end
多个UITableView横向切换的简单实现(有点类似网易新闻)的更多相关文章
- 用jquery来实现类似“网易新闻”横向标题滑动的移动端页面
HTML: <div id="navbar"> <div id='navbar_content' style="left:0px;"> ...
- 基于jQuery仿Flash横向切换焦点图
给各网友分享一款基于jQuery仿Flash横向切换焦点图.利用Flash可以制作很多漂亮的图片相册应用,今天我们要用jQuery来实现这样的效果.它是一款仿Flash的横向图片切换焦点图插件,可以自 ...
- Swift - UITableView状态切换效果
Swift - UITableView状态切换效果 效果 源码 https://github.com/YouXianMing/Swift-Animations // // TableViewTapAn ...
- AbstractRoutingDataSource 实现动态数据源切换原理简单分析
AbstractRoutingDataSource 实现动态数据源切换原理简单分析 写在前面,项目中用到了动态数据源切换,记录一下其运行机制. 代码展示 下面列出一些关键代码,后续分析会用到 数据配置 ...
- 【转】 iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
原文:http://blog.csdn.net/hmt20130412/article/details/34523235 本来只是打算介绍一下addChildViewController这个方法的,正 ...
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
本文转载至 http://www.tuicool.com/articles/3ymMzub CSDN博客原文 http://blog.csdn.net/hmt20130412/article/det ...
- 转:addChildViewController实现网易新闻首页切换
本来只是打算介绍一下addChildViewController这个方法的,正好今天朋友去换工作面试问到网易新闻标签栏效果的实现,就结合它,用个小Demo实例介绍一下:(具体解释都写在了Demo里面的 ...
- ViewPager图片切换的简单案例
1)ViewPager类直接继承了ViewGroup类,所有它是一个容器类,可以在其中添加其他的view类. 2)ViewPager类需要一个PagerAdapter适配器类给它提供数据. 向右滑动切 ...
- ImageSwitcher图片切换的简单用例
ImageSwitcher的原理:ImageSwitcher有两个子View:ImageView,当左右滑动的时候,就在这两个ImageView之间来回切换来显示图片 实现左右滑动切换图片 BaseA ...
随机推荐
- ALM11需求类型
- 与IO相关的等待事件troubleshooting-系列9
Buffer Cache与IO相关的等待事件: 这种等待事件的产生原因是包含DBWR进程和IO Slaves的Buffer Cache操作. 'db file parallel write' , 'd ...
- Dijkstra in python
下面是一段由python实现的Dijkstra算法,一些地方的处理实在非常棒,相比于C,代码的数量已经缩减到了60行,所以我想通过本文简单的介绍一下这段代码的细节之处,首先给出源程序: from sy ...
- mysql数据库全局只读和会话只读问题解析
对于系统的发布是经常有的事情,有些时候需要隔绝外界对数据库的更改但是还要求可以读取数据,对于mss sql 这个就是很简单,直接属性—>选项—>只读 ,但是对于mysql这是不同的,今天仔 ...
- U盘安装SLES的方法
安装准备: 一个4G 或 大于4G的U盘 也同样适合移动硬盘, SLES-11-DVD-i586-GM-DVD1.iso 文件1) 将U盘格式化成FAT32格式; 2) 下载 syslinux工具 h ...
- 教你50招提升ASP.NET性能(三):使用Microsoft的PDBs调试和分析外部的程序集和库
(3)Use Microsoft’s PDBs to debug or profile external assemblies or libraries 招数3: 使用Microsoft的PDBs调试 ...
- Aizu 2304 Reverse Roads 费用流
Reverse Roads Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- java基础复习之对于String对象,能够使用“=”赋值,也能够使用newkeyword赋值,两种方式有什么差别?
String类型是实际工作中经经常使用到的类型,从数据类型上划分,String是一个引用类型,是API中定义的一个类.所以String类型的对象能够用new创建,比如String name=new S ...
- 应聘.net开发工程师常见的面试题(一)(转载)
1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...
- tar备份系统
一.概述 前几天我通过SSH正在调戏汤姆猫(tomcat)的时候,服务器上CentOS突然挂了.开机grub,使用光盘linux rescue修复提示找不到linux分区,然后想mount硬盘备份系统 ...