的下标 NSIndexPath *firstIndexPath = [[self.collectionView indexPathsForVisibleItems] firstObject];...// 赋值给记录当前坐标的变量 self.pageControl.currentPage = firstIndexPath.row; } 设置Header或Footer 生成头 我这里用的xib...,对应的class文件如下 class QuestionBookHeader: UICollectionReusableView { @IBOutlet weak var titleLabel:...QuestionBookHeader; if(indexPath.section == 0){ header.titleLabel.text = "我的分类" }else...let attribute = UICollectionViewLayoutAttributes(forCellWithIndexPath:indexPath) //当前行的Y
项目中想实现空态页风格统一控制的效果,就封装了一个默认空态页,使用的技术点有:1 方法替换 ,2 给分类(Category)添加属性。 ...但是分类(Category)不可以,但是我们又想在原生的UITableView和UICollectionView上添加空态页,所以使用了黑科技runtime中提供的对象关联。
UIScrollView 恐怕是所有 App 都绕不过去的类——尤其是它的子类 UITableView 和 UICollectionView。...如何定制不同 Cell 的 UI、如何与用户交互、如何与服务器端数据同步、如何在滑动时最大限度保证界面的流畅,这些都是考察的要点,是一个 iOS 工程师必备的基本技能。...关键词:#UITableViewDataSource #UITableViewDelegate #refreshControl 本题主要考察 UITableView 最基本的用法:主要涉及 UITableViewDataSource...预加载的原理就是,根据当前 UITableView 所在位置,除以目前整个 contentView 的高度,来判断当前位置是否超过 Threshold,如果超过,就发起网络请求,获得数据。...该方法发生在 UICollectionView 数据准备好,但界面还未布局之时。它用于计算各种布局信息,并设定每个 item 的相关属性。
在 iOS 13 中 Apple 为 UITableView 和 UICollectionView 引入了 DiffableDataSource,让开发者可以更简单高效的实现 UITableView、UICollectionView...的局部数据刷新。...下面以 UITableView 为例进行讲解。 实现步骤 使用 DiffableDataSource 配置当前 UITableView 的数据源。...DiffableDataSource 通过调用自身 apply 方法将 DataSourceSnapshot 变更后的数据更新同步到 UITableView。...UITableView 的关键使用步骤,UIColletionView 使用类似,完整案例详见下面的链接: UITableView案例 UICollectionView案例
UITableView 3.1 通过屏幕点击改变的选中状态回调给代理 //选中 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath...:(NSIndexPath *)indexPath; 3.2 代码设置默认选中状态 (要等数据加载完成之后再调用) 执行方法的主体:tableview对象 //选中 - (void)selectRowAtIndexPath...UICollectionView 4.1 通过屏幕点击改变的选中状态回调给代理 //选中 - (void)collectionView:(UICollectionView *)collectionView...collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath; 4.2 代码设置默认选中状态 (要等数据加载完成之后再调用) 执行方法的主体...cell的时候,UITableView并不会执行- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath
平常我在业务开发中,绝大部分情况都是使用的UITableView,而UICollectionView则是在极少情况下才会去使用,这就导致了我对UICollectionView略感陌生。...UICollectionView的collectionCell支持横向&纵向布局,比UITableView的tableCell只有纵向布局要更加灵活。...UICollectionView和UITableView有相同的API设计理念——都是基于dataSource以及delegate驱动的。...UITableView中的row,对应到UICollectionView中就是item,因为一行可以展示多个cell,使用row(行)不能准确地表达。...,这是UITableView和UICollectionView的最大的不同。
UICollectionView 是在UITbableView 之后出现的一种方便列布局的试图控件。...UICollectionView 的宽度 - 可容纳的item的宽度之和 再平分之后的距离就是每个Item之间的间距。 ?...上的数据都是取自于它所以,此处应该把数据源也随着移动更新下 - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath...使用UITableView,这种方式应该是最易想到的,因为需要展现几列就用几个tabelview就ok了,而且不需要考虑重用,因为苹果已经做好了,只需要考虑如何在几列tabelView滑动的时候,保持同步不出现...使用UICollectionView,UICollectionView在iOS6中第一次被介绍,它与UITableView有许多相似点,但它多了一个布局类,而实现瀑布流,就与这个布局类有关。
引 开发中我们最常看到的可能是表视图UITableView了,但其实还有一个视图也很常见,特别是一些图片、商品、视频的展示界面,用UICollectionView来展现往往会更加方便。...如果熟悉UITableView的话,其实很多地方都是类似的,甚至可以说UITableView是一种特殊的UICollectionView,正如正方形是一种特殊的矩形一样,UITableView就是一种每行只放一个方块的...其实看代码的也会发现两者之间有着惊人的相似。 自定义Cell 根据UITableView的经验。...控制器 接着我们来创建UICollectionView,UICollectionView和UITableView的相同之处在于它们都是由DataSource填充内容并有Delegate来管理响应的,并且都实现了循环利用的优化...的使用方式,就像UITableView可以简单也可以做的非常多样,UICollectionView也是一种乍看很平常但可以容纳非常多想象力的布局方式,只要善加利用就可以做出很好的效果,当然,什么时候用UICollectionView
XYPieChart -XYPieChart:饼状图, 饼图, 数据统计, 数据可视化,可以在图形上标注数据。效果十分漂亮,而且没有用到一张图片。...ZFChart - 模仿PNChart写的一个图表库,用法简单,暂时有柱状图,线状图,饼图三种类型,后续可能会更新新的类型。...UITableView-FDTemplateLayoutCell - UITableView-FDTemplateLayoutCell 是一个方便缓存 UITableViewCell 的高度的框架。...LLNoDataView - 超简单的空数据提示通用View支持UIScrollView、UITableView、UICollectionView、UIWebView。...YX_UITableView_IN_UITableView - UITableview嵌套UITableView案例实践(仿淘宝商品详情页实现),项目讲解。
1 定义 1.1 什么是UICollectionView UICollectionView是一种新的数据展示方式,简单来说可以把他理解成多列的UITableView(请一定注意这是UICollectionView...最简单的UICollectionView就是一个GridView,可以以多列的方式将数据进行展示。...1.3 关于重用 为了得到高效的View,对于cell的重用是必须的,避免了不断生成和销毁对象的操作,这与在UITableView中的情况是一致的。...首先UICollectionViewCell不存在各式各样的默认的style,这主要是由于展示对象的性质决定的,因为UICollectionView所用来展示的对象相比UITableView来说要来得灵活...1.6 UICollectionViewLayout 这是UICollectionView和UITableView最大的不同。
1,iOS10 新增的privacy settings iOS10添加了新的权限控制范围 如果你尝试访问这些隐私数据时得到如下错误: > This app has crashed because it...NSCameraUsageDescription key with a string value explaining to the > user how the app uses this data 因为它企图访问敏感数据时没有在应用程序的...性能优化 在iOS10 UICollectionView 最大的改变是增加了Pre-Fetching(预加载), 如果你翻看UICollectionView的最新API你可以发现新增了如下属性: @...性能优化 和UICollectionView一样UITableView也增加了Pre-Fetching技术,UITableView新增了如下属性: @property (nonatomic, weak...) id prefetchDataSource NS_AVAILABLE_IOS(10_0); 奇怪的是UITableView并没有找到
使用UITableView就不用考虑复用以及调整scrollView上子控件位置的问题了。...手动敲代码利用UITableView实现具有需求效果的控件,可当UITableView滑动到最后一个cell再滑动到第一个cell的时候出现问题(并不能很流畅地从最后一个cell滑动回第一个cell)。...手动敲demo: 先在当前控制器的view上添加一个UICollectionView,每个item的大小等于UICollectionView的大小。...再添加一个定时器,每隔一定的时间让UICollectionView进行滚动。...] lastObject]; // NSLog(@"current:%lu", currentIndexPath.row); // 马上显示回最中间那组的数据 NSIndexPath
数据联动 在某一列滚动的时候,重新设置联动列的显示数据,然后进行刷新操作。...,而且可以更简单高效的实现数据的刷新。...类似 UITableView,需要提供数据源以显示数据。...UICollectionViewFlowLayout 与 UITableView 不同,UICollectionView 需要提供布局参数,常用的有UICollectionViewFlowLayout,...iOS 14 中 UICollectionView 的功能得以继续增强,可以在一定程度上替换 UITableView。
iOS中,UICollectionView和UITableView已经有系统默认选中颜色设置,但是只有无色,蓝色,灰色,三种颜色设置,如果想要其他的颜色效果,我们可以自由自定义设置。...前言 先观赏一下典型的UITableView控件案例 ? image.png 典型的UICollectionView控件案例 ?...:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { // return...- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath...注意的是,方案一和方案二不要重复设置。另外,二者择一的话,推荐方案一。
iOS 14 中 UICollectionView 的功能继续增强,可以在一定程度上替换 UITableView。本文以一个案例的形式看看如何使用。...依然使用 iOS开发之DiffableDataSource 一文中的数据。 需要熟悉 DiffableDataSource 的基本使用。...创建UICollectionView extension ViewController { // 创建列表式UICollectionView func makeCollectionView...(frame: view.frame, collectionViewLayout: layout) } } 注册Cell 这是核心,在这里可以像 UITableView 一样,填充 Cell 的内容...extension ViewController { // 注册Cell,这里用的是默认的UICollectionViewListCell,也可以用自定义的cell func makeCellRegistration
介绍 WWDC 2019 推出了上下文菜单(Context Menus)成为 3DTouch 的替代品。 需要通过长按方式触发。...如果要启用上下文菜单,需要创建一个 UIContextMenuInteraction 并将其添加给某个触发的 UIView,然后指定 delegate,实现代理方法。...效果 UITableView和UICollectionView iOS 13 以后,UITableView 和 UICollectionView 也支持 Context Menus,使用起来特别简单,只需要实现相应的代理方法...UITableView func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath...func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath:
而且更重要的是,在屏幕外面等待加载的cell是整整一行!这一行的cell都已经加载完数据。这是UICollectionView在用户大幅度滑动时卡顿的根本原因。用专业的术语来说,掉帧。...性能的提升和UICollectionView一样的,对UITableView的性能提升很大! 四....Interactive Reordering 谈到重新排列,这是我们就需要类比一下UITableView了,UICollectionView的重新排列就如同UITableView 把cell上下移动,只不过...UITableView的重排是针对垂直方向的。...总结 通过以上,我们谈到了以下的知识: UICollectionView cell pre-fetching预加载机制 UICollectionView and UITableView prefetchDataSource
739006-20160607165303027-1215360678.png 先说说控制器里面的代码,控制器里面就是我们的 UICollectionView 的一些基本的创建了。...其实它和 UITableView 相比较的话,但从创建使用看的话,是挺相似的,但其实它真的比 UITableView 要强大好多!很值得大家去好好的学习学习!...你要占我它的基本创建的话,可以参考 UITableView ,参考对比也有利于学习。...上面的控制器说完了,就到重点了,也就是继承与 UICollectionViewFlowLayout 的 zxFlowLayout ,有一点大家注意一下,就是你在初始化UICollectionView....h 文件里面也就只有 itemcount 这一个属性了,这个属性其实在你控制器当中你刷新完数据之后就传过来。让它重新布局就OK了!挺简单的对吧。。
UICollectionView 1.必须要设置布局参数 2.注册cell 用法类似于UITableView 类。自动实现重用,必须注册初始化。...(用作背景展示) 一、UICollectionViewLayout UICollectionView的精髓 Layout决定了UICollectionView是如何显示在界面上的。...UICollectionViewLayout的功能为向UICollectionView提供布局信息....二、UICollectionView 1.UICollectionViewDataSource ①section的数量 -numberOfSectionsInCollection: ②某个section...:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath; // 下面是三个和高亮有关的方法
{ return 10; } //定义展示的Section的个数 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)...collectionView { return 2; } //每个UICollectionView展示的内容 -(UICollectionViewCell )collectionView:(UICollectionView...的 margin -(UIEdgeInsets)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout...被选中时调用的方法 -(void)collectionView:(UICollectionView )collectionView didSelectItemAtIndexPath:(NSIndexPath...如果要永久改变,可以先改数据源,然后在cellForItemAtIndexPath中控制。(和UITableView差不多吧!
领取专属 10元无门槛券
手把手带您无忧上云