ios - Property 'label' not found on object of type
黄舟
黄舟 2017-04-17 15:16:55
[iOS讨论组]

1,这是一个collection view的简单程序。每个cell包含一个label显示一个1-200的数字
2,定义了一个CollectionViewCell类,一个继承它的GridCell类。
3,storyboard中,cell的类为GridCell,identifier为GridCell
4, label是GridCell的属性,用来显示数字
CollectionViewController的以下方法中,总是报错,找不到celllabel属性:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GridCell" forIndexPath:indexPath];

    NSNumber *number = numbers[indexPath.row];

    cell.label.text= [number description]; //这句报错,Property 'label' not found on object of type'UICollectionViewCell'

    return cell;
}
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(2)
PHP中文网
 UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GridCell" forIndexPath:indexPath];

问题在这一句,你用父类声明的,怎么能调用到子类的属性
按你描述,应该用GridCell声明

迷茫

原因是 cell应该是GridCell,放在这里供大家参考吧。

有没有提供ios开发这种实习的岗位的?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号