【发布时间】: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