【发布时间】:2013-01-23 03:07:51
【问题描述】:
我正在创建一个 CollectionView 应用程序。我通过 JSON 字符串从服务器获取数据。我的工作流程如下
-
创建的集合视图单元格为 ProjectVCollectionViewCell.h、.m、.xib。
.h 的代码是 -
@interface ProjectCollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *projectImage;
@property (weak, nonatomic) IBOutlet UILabel *projectLabel;
@结束
.m 的代码是默认的,并综合了上述 2 个变量。 并且 .xib 具有带有图像视图和标签的集合视图单元(将上述类与集合视图单元链接并将标识符名称链接为“projectCell”。
- 其ViewController的代码,包含collectionView,如下
ViewController.m 里面的代码是
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section{
return [projectList count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
ProjectCollectionViewCell *cell = (ProjectCollectionViewCell *)[cv dequeueReusableCellWithReuseIdentifier:@"projectCell" forIndexPath:indexPath];
cell.projectLabel.text = @"";//Here i am getting issue
//cell.projectLabel.text = [[NSString alloc] initWithString:[[projectList objectAtIndex:indexPath.row] objectForKey:@"albumName"]];
return cell;
}
在上面的代码中 cell.projectlabel 给了我问题
[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0
2013-02-07 20:08:17.723 Sample[3189:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0'
*** First throw call stack:
单元格值很好,我用 NSLog 跟踪到,代码提示也在“。”之后使用 projectLabel。但我无法通过这个设置标签字段值。所以请帮帮我。
【问题讨论】:
-
你注册nib了吗?
-
是的。如下 - [self.projectListView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"projectCell"];
-
@Sang 你真是个天才。 :)。你救了我的命。请将此作为您的答案。我会将其视为解决方案。
标签: uicollectionview uicollectionviewcell