必须指定’UICollectionView的布局对象,如果没有,则不能使用其进行布局.那么就意味着我们必须传入一个布局对象,也就意味着只能通过[[UICollectionView alloc] initWithFrame:<#(CGRect)#> collectionViewLayout:<#(nonnull UICollectionViewLayout *)#>];
来创建UICollectionView控件
我的代码
_tableview = [[UICollectionView alloc]init];
_tableview.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
_tableview.contentInset = UIEdgeInsetsMake(APP_NAVIGATION_BOTTOM, 0, APP_BOTTOM_PADDING, 0);
/_tableview.collectionViewLayout = layout;
_tableview.delegate = self;
_tableview.dataSource = self;
_tableview.backgroundColor = self.view.backgroundColor;
然后一运行就报错
修改后
_tableview = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) collectionViewLayout:layout];
//_tableview.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
_tableview.contentInset = UIEdgeInsetsMake(APP_NAVIGATION_BOTTOM, 0, APP_BOTTOM_PADDING, 0);
//_tableview.collectionViewLayout = layout;
_tableview.delegate = self;
_tableview.dataSource = self;
_tableview.backgroundColor = self.view.backgroundColor;