我在iOS中对子类化UIViewController感到困惑,我有一个父视图控制器,它符合UICollectionViewDataSource协议(在其实现文件中的私有接口中)。
/* Parent.m */
@interface Parent () <UICollectionViewDataSource>
// this CollectionView is connected to storyboard
@property (weak, nonatomic) IBOutlet UICollectionView *CollectionView;
@end
@implementation Parent
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.somecount;
}
@end
然后我创建了一个继承自父视图控制器的子视图控制器。由于数据源是在父视图控制器的私有接口中实现的,因此子视图控制器对UICollectionViewDataSource一无所知。
/* child.h */
@interface child : parent
// nothing was mentioned here that parent has a method to set the count using 'somecount'
@end
然后我将主storyboard中的视图控制器设置为子视图控制器。
iOS如何从父属性'somecount'获取值并为子项设置值?
谢谢。