Home  >  Q&A  >  body text

ios - Property 'label' not found on object of type

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

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:18:55

     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

    reply
    0
  • 迷茫

    迷茫2017-04-17 15:18:55

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

    Are there any internship positions for iOS development?

    reply
    0
  • Cancelreply