I'm new to iOS development. I need to use a CollectionView without using Storyboard and this view has to be load in a tab. Is this possible.
Thanks
I'm new to iOS development. I need to use a CollectionView without using Storyboard and this view has to be load in a tab. Is this possible.
Thanks
Ya. you can create it programmatically
-(void)loadView
{
[super loadView];
UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init];
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
[self.collectionView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
[self.collectionView setBackgroundColor:[UIColor clearColor]];
[self.collectionView registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:@"Cell"];
[self.view addSubView:self.collectionView];
}
You have to create a UIViewController subclass that implements UICollectionViewDataSource and UICollectionViewDelegate like this:
@interface MyViewController:UIViewController<UICollectionViewDelegate, UICollectionViewDataSource>
@end
then in the .m file you implement the required UICollectionViewDataSource and UICollectionViewDelegate Methods
and override -[UIViewController viewDidLoad] like so:
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionView *collectionView = [UICollectionView alloc] initWithFrame:self.view.bounds];
collectionView.delegate = self;
collectionView.dataSource = self;
[self.view addSubview:collectionView];
}