tabelVew嵌套CollectionView
来源:互联网 发布:mac口红cb96好看吗 编辑:程序博客网 时间:2024/06/07 03:17
重要的写在前面,写了一个tabelVew嵌套CollectionView的使用方法,相关的demo请点击demo链接
简单的说,就是每一个tabelVewCell里面都包含一个CollectionView.
其实思路很简单的:
1.创建一个tableVIew
加入数据源,加入tableView如果需要加入一个头视图,加入代理方法
-(UITableView *)tableView{if (!_tableView) {_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0 , SCREEN_WIDTH, SCREEN_HEIGHT)];_tableView.backgroundColor =[UIColor whiteColor];_tableView.dataSource =self;_tableView.delegate = self;[_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];_tableView.showsVerticalScrollIndicator = NO;[_tableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:@"HomeTableViewCell"];UIImageView *headerView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];headerView.image = [UIImage imageNamed:@"风景1.jpg"];_tableView.tableHeaderView = headerView;[_tableView reloadData];}return _tableView;}#pragma mark - tableViewData 代理方法-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return self.dataArray.count;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}
2.自定义tableVIewCell,每个tableVIewCell里面搞个collectionVIew
//在cell的初始化方法里面搞一个collectionVIew- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{}//在layoutSubviews计算每个tableVIewCell的collectionVIew的大小- (void)layoutSubviews{[super layoutSubviews];}#pragma mark -- Collection delegate//这是UICollectionView的点击方法,如果点击每个UICollectionViewCell需要在viewController里面响应的话。需要自定义一个代理方法- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {if([self.delegate respondsToSelector:@selector(CustomCollection:didSelectRowAtIndexPath:str:)]){[self.delegate CustomCollection:collectionView didSelectRowAtIndexPath:indexPath str:self.collectDataArray[indexPath.row]];}}
3.自定义一下collectionVIewCell
自定义collectionVIewCell
需要计算一下根据屏幕的宽度,没行可以显示几个
总结:有很多的项目中tabelVew嵌套CollectionView其实每个cell就是一行CollectionView,例如AppStore,这种只要设置CollectionView水平方向滑动就好了。
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
在iOS的开发过程中,如有问题可以与我联系!
邮箱:2877025939@qq.com
阅读全文
0 0
- tabelVew嵌套CollectionView
- collectionView中嵌套tableView
- tableviewcell嵌套collectionview
- 自定义TableViewCell里嵌套CollectionView
- CollectionView
- collectionView
- collectionView
- collectionView
- CollectionView
- CollectionView
- collectionView
- collectionView
- CollectionView
- collectionView
- collectionview
- CollectionView嵌套TableView。页面滑动指向不同的标题
- Customised collectionView
- collectionView学习
- CSS常见问题及解决(三)自己写下拉框逻辑,鼠标离开下拉框时,下拉出来的div会消失
- vs2003生成的程序,启动默认以管理员身份运行
- Java 并发编程:线程间的协作(wait/notify/sleep/yield/join)
- Java之Socket与HTTP区别
- 深度学习
- tabelVew嵌套CollectionView
- python文件操作
- 算法设计与分析 01背包 动态规划
- java中的值类型int与引用类型integer
- 网页中实现 js 繁体简体切换
- url-时间戳用法
- 三维模型重建(1):关于三维模型重建的一些简介
- 流程图制作软件
- AI,爱