ios - Property 'label' not found on object of type
黄舟
黄舟 2017-04-17 15:16:55
0
2
869

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;
}
黄舟
黄舟

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

reply all(2)
洪涛
 UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GridCell" forIndexPath:indexPath];

The problem is in this sentence, you declare it with the parent class, how can you call the attributes of the subclass
According to your description, GridCell should be declared

迷茫

The reason is that cell should be GridCell, let’s put it here for your reference.

Are there any internship positions for iOS development?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template