我试图预选上负载的第一集合观察室,但项目没有预选负载我用来预选集合观察室第一项没有预选
代码如下
MenuBar.m // Type UIView <UICollectionViewDelegate ,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
...
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
....
// below code in -(instancetype)initWithFrame:(CGRect)frame
NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[collectionView selectItemAtIndexPath:selectedIndexPath
animated:false
scrollPosition:UICollectionViewScrollPositionNone];
....
// below code in -(instancetype)initWithFrame:(CGRect)frame
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
为什么要调用collectionView:didSelectItemAtIndexPath?你在班上实施了这个方法吗? –