1,这是一个collection view
的简单程序。每个cell
包含一个label
显示一个1-200的数字
2,定义了一个CollectionViewCell
类,一个继承它的GridCell
类。
3,storyboard中,cell的类为GridCell
,identifier为GridCell
4, label是GridCell
的属性,用来显示数字
在CollectionViewController
的以下方法中,总是报错,找不到cell
的label
属性:
- (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;
}
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 beGridCell
, let’s put it here for your reference.Are there any internship positions for iOS development?