UICollectionView未正确更新 - 使用THStringyFlowLayout(UICollectionView is not updating properly - used THStringyFlowLayout)
当我的应用程序启动时,它会从持久性中获取数据并在我的集合视图中显示5个单元格。 这些单元格看起来像普通的TableView单元格,但我使用Collection View进行后续的布局调整。 整个屏幕需要8个单元格。
之后的第二秒,使用19个单元格的数据更新模型,并通过调用以下内容更新集合视图:
[self.collectionView reloadData];
已经显示5个单元格的那些用新数据很好地刷新,但就是这样。 直到我触摸屏幕并向下滚动单元格的高度,才会显示其他单元格。 然后立即显示3个单元格并填充屏幕。 从那一刻起,一切都很好,但在滚动之前,它没有正确更新。
当我调试它时,我看到,在调用reloadData之后调用collectionView:numberOfItemsInSection:它返回正确的数字19,但是只询问那些5个单元格的collectionView:cellForItemAtIndexPath:(直到我滚动)。
有点绝望,谢谢你的帮助。
编辑 - 添加源代码:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.manager.jubilees count]; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { DLog(@"asked for cell: %i", indexPath.row); //just for debugging to know, what is going on JUJubileeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"JubileeCell" forIndexPath:indexPath]; cell.jubilee = self.manager.jubilees[(NSUInteger) indexPath.row]; return cell; } // called when model is updated -(void)jubileesUpdated { DLog(@"jubileesUpdated"); [self.collectionView reloadData]; }
编辑2:当加载前5个单元格时,[self.collectionView contentSize]为(width = 320,height = 358)。 当加载所有19个单元格并调用reloadData时,contentSize为(width = 320,height = 1366) - 但实际上并未显示单元格:(。
编辑3:问题是由使用THStringyFlowLayout引起的 - 如果我找到原因,我会发布更多内容。
When my app starts, it takes data from the persistence and displays 5 cells in my Collection View. These cells looks like normal TableView cells, but I use Collection View for later layout tweaks. It takes 8 cells to fill whole screen.
A second after that, the model is updated with the data for 19 cells and the Collection View is updated by calling:
[self.collectionView reloadData];
Those already displayed 5 cells are nicely refreshed with new data, but that's it. The other cells are not displayed until I touch the screen and scroll down about the height of the cell. Then instantly 3 cells are displayed and fills the screen. From that moment, everything is fine, but until I scroll, it is not updated correctly.
When I debugged it, I see, that the collectionView:numberOfItemsInSection: is called after calling reloadData and it returns correct number 19, but the collectionView:cellForItemAtIndexPath: is asked just for those 5 cells (until I scroll).
Kind of desperate here, thanks for your help.
Edit - added source code:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.manager.jubilees count]; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { DLog(@"asked for cell: %i", indexPath.row); //just for debugging to know, what is going on JUJubileeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"JubileeCell" forIndexPath:indexPath]; cell.jubilee = self.manager.jubilees[(NSUInteger) indexPath.row]; return cell; } // called when model is updated -(void)jubileesUpdated { DLog(@"jubileesUpdated"); [self.collectionView reloadData]; }
edit 2: When first 5 cells are loaded, the [self.collectionView contentSize] is (width=320, height=358). When the all 19 cells are loaded and reloadData called, contentSize is (width=320, height=1366) - but cells are not actually displayed :(.
edit 3: The problem is caused by using THStringyFlowLayout - I will post more, if I find the reason.
原文:https://stackoverflow.com/questions/22335503
满意答案
借助jquery,您可以获得渲染图像的高度。
然后,您只需更改偏移参数。 这是一支笔: https : //codepen.io/anon/pen/KyQddz
<div class="navbar"> This is my navbar </div> <figure> <img src="https://via.placeholder.com/350x80" /> </figure> * { margin: 0; padding:0; box-sizing: border-box; } .navbar { background: red; width: 100%; height: 60px; position: fixed; top:0; } .shrink { background: green; } figure { height: 2000px; } img { display: block; width: 100%; height: auto; } var imgHeight; $(window).on('load', function () { imgHeight = $('img').height(); }); $(window).scroll(function() { if ($(document).scrollTop() > imgHeight) { $('.navbar').addClass('shrink'); } else { $('.navbar').removeClass('shrink'); } });
如果你想让导航栏只在你滚动图像的高度后才能修复,只需要移动
position:fixed;top:0;
到.shrink
类。.navbar { background: red; width: 100%; height: 60px; } .shrink { background: green; position: fixed; top:0; }
You can get the height of your rendered image thanks to jquery.
Then, you simply change the offset parameter. Here is a pen: https://codepen.io/anon/pen/KyQddz
<div class="navbar"> This is my navbar </div> <figure> <img src="https://via.placeholder.com/350x80" /> </figure> * { margin: 0; padding:0; box-sizing: border-box; } .navbar { background: red; width: 100%; height: 60px; position: fixed; top:0; } .shrink { background: green; } figure { height: 2000px; } img { display: block; width: 100%; height: auto; } var imgHeight; $(window).on('load', function () { imgHeight = $('img').height(); }); $(window).scroll(function() { if ($(document).scrollTop() > imgHeight) { $('.navbar').addClass('shrink'); } else { $('.navbar').removeClass('shrink'); } });
If you want the navbar the be fixed only after you scroll the height of the image, just move
position:fixed;top:0;
to the.shrink
class..navbar { background: red; width: 100%; height: 60px; } .shrink { background: green; position: fixed; top:0; }
相关问答
更多导航栏下的Bootstrap轮播(Bootstrap carousel under navbar)
让文本显示在导航栏下(Getting text to appear under navbar)
Odoo博客封面图片没有显示(Odoo blog cover image not showing)
为什么我的常规导航栏覆盖标题,而折叠的标题没有?(Why does my regular navbar cover header while the collapsed one does not? (bootstrap/fullpage))
斜杆上的Navbar(Navbar on Slanted Div)
如何删除导航栏徽标和导航栏菜单之间的空格以及文本后面的导航栏徽标(How to remove the space between navbar logo and navbar menu and navbar logo behind the text)
缩小导航栏后封面图片(Shrink navbar AFTER cover image)
如何在twitter boostrap导航栏中使用背景图片?(how to use background image in twitter boostrap navbar?)
从ios中的epub获取封面图片(fetch Cover Image from epub in ios)
如何在封面图片下方放置文字?(How to put text below the cover image?)
相关文章
更多fw:Hadoop、Pig、Hive、Storm、NOSQL 学习资源收集【Updating】
顶 Hadoop、Pig、Hive、Storm、NOSQL 学习资源收集【Updating】
nginx禁止未绑定域名访问
usic AS下如何正确设置solr
Apache Hadoop未指明用户模拟漏洞
Solr范围查询,结果不正确问题
[转] 米聊PK微信:未开战即结束
怎样正确查看Linux的内存占用情况
Hadoop lzo 正确安装及问题解决
你的服务器没有正确响应Token验证的解决方法
最新问答
更多如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
linux的常用命令干什么用的
由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
如何交换返回集中的行?(How to swap rows in a return set?)
在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
Java中的不可变类(Immutable class in Java)
WordPress发布查询(WordPress post query)
如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!