【发布时间】:2013-05-15 21:29:47
【问题描述】:
我已经用自定义和标准UITableView 单元完成了几十次。我所有的插座都已连接。 UILabel 是我在 IB 中的 UICollectionViewCell 的子视图。我的UICollectionViewCell 对象继承了身份检查器中的正确类。
如何在UICollectionViewCell 上设置UILabel?
MyCell.m
-(void)setCellName:(NSString *)cellName {
self.cellLabel.text = cellName;
}
ViewController.m
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ADMCell *cell =
(ADMCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"ADMCell"
forIndexPath:indexPath];
[cell setCellName:[NSString stringWithFormat:@"%d",[indexPath row]]];
return cell;
}
cell.debugDescription 的输出:
2013-05-15 22:05:40.191 ProductName[857:c07] cell.debugDescription:
<ADMCell: 0xb35c890; baseClass = UICollectionViewCell;
frame = (245 266; 70 80); layer = <CALayer: 0xb35c780>>`
【问题讨论】:
-
您是否将 IB 中的单元格设置为具有正确的标识符“ADMCell”以便正确出列?
-
你可以在分配标题后使用 NSLog("%@",cell.debugDescription) 吗?以防万一 cell 为零...并确认 @"AMDCell" 是唯一注册的。
-
那你有什么问题?
self.cellLabel是零吗?细胞是错误的细胞类型吗?如果您不告诉我们,我们不知道出了什么问题。 -
Dan Fairaizl,标识符设置为 ADMCell。亚历克斯,我已经包含了上面的输出。很抱歉缺少细节。 @Caleb
setCellName:从不在单元格上设置标签。 Check out this screenshot. -
mmmm... 好的.. 如果您在 -cellForItemAtIndexPath:(NSIndexPath *)indexPath 中设置断点,并检查 cell.cellLabel,它是否包含预期的文本?还有文字标签,以防万一,前面有什么东西会混淆视图?
标签: iphone ios uicollectionview uicollectionviewcell