【问题标题】:UICollection View ios 7 issuesUICollectionView ios 7 问题
【发布时间】:2013-09-25 17:08:20
【问题描述】:

我正在将此代码用于我的 UIcollectionView,它在 iOS6 中工作正常,但在 ios7 中它不工作,因为一旦我开始滚动 CollectionView,整个元素的方向就搞砸了。 对此有任何想法

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.filteredNewsItems.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NewsItemCell *cell = (NewsItemCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.autoresizingMask = UIViewAutoresizingNone;

[cell loadWithArticle:self.filteredNewsItems[indexPath.item]];

return cell;
}

【问题讨论】:

  • 你能提供截图吗?
  • 添加了快照。
  • 这也只发生在 scroll 之后,否则它看起来很好并且有方向性。

标签: ios objective-c ios7 uicollectionview


【解决方案1】:

尝试使用

 static NSString *cellIdenfier = @"collectionCell"; // this can be any string
NewsItemCell *cell = (NewsItemCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdenfier forIndexPath:indexPath];

您的单元格搞砸了,因为在重新使用滚动单元格时,在您的情况下,提供静态单元格标识符可以解决您的问题。 如果问题仍然存在,请告诉我

【讨论】:

  • 好吧,我正在做同样的静态 NSString *reuseIdentifier = @"NewsItemCell"; ,所以它不适用于 ios7
  • 那么你在哪里定义你的标识符字符串?并设置一个断点并打印您是否获得了正确的值
  • 它在文件顶部全局定义。
  • 您是否尝试在单元格中为索引处的行打印标识符?你得到了正确的价值吗?
【解决方案2】:

我怀疑您的 loadWithArticle: 方法总是向 NewsItemCell 添加视图,而不是重用您第一次填充单元格时创建的任何现有子视图。能否提供 loadWithArticle: 的代码?

【讨论】:

    猜你喜欢
    • 2020-02-26
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多