【问题标题】:UICollectionReusableView for section header not working节标题的 UICollectionReusableView 不起作用
【发布时间】:2014-01-21 14:59:02
【问题描述】:

我为 UICollection 视图部分标题创建了一个 UICollectionReusuable 视图。我使用以下代码来实现标题视图。

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
ThemeHeader *headerView = [[ThemeHeader alloc] init];
headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                                                 withReuseIdentifier:@"header"
                                                                        forIndexPath:indexPath];
NSString *title = @"Title for the header";
headerView.title.text = title;
return headerView;

}

它崩溃给我以下错误:

-[UICollectionReusableView 标题]:无法识别的选择器发送到实例 0xac846a0'

我的 ThemeHeader 类看起来像这样

@interface ThemeHeader : UICollectionReusableView
@property (strong, nonatomic) IBOutlet UILabel *title;

@end

提前感谢您的帮助。

【问题讨论】:

  • 为什么要创建 headerView 然后用 dequequed View 重新初始化?
  • 您的标题 IBOutlet 是否正确连接到其笔尖上的相应 UILabel?
  • 您是否使用以下方法注册类 registerClass:forSupplementaryViewOfKind: withReuseIdentifier: 用于您的补充视图?

标签: ios objective-c uicollectionview uicollectionreusableview


【解决方案1】:

这意味着headerView 不是您所期望的ThemeHeader 的实例,而是UICollectionReusableView 的实例,它没有title 属性。

这可能是因为您可能没有在故事板上的身份检查器中将 ThemeHeader 设置为自定义类以用于此可重用视图。

【讨论】:

  • 不知道为什么这会被否决。对我来说似乎是一个很好的答案。
  • 这就是问题所在。谢谢
猜你喜欢
  • 1970-01-01
  • 2013-05-10
  • 1970-01-01
  • 2023-03-15
  • 2015-10-16
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多