Reputation: 346
I would like to know what would be the best way to implement an android like view pager with tabs on iOS like the one found on the FIFA world cup app
The various approaches that I could think of were:
My current implementation- I have three tab bar entries as of now. I have separate view controllers for each of them. Here is the way I implemented it using horizontal paging collection view:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSInteger indexNumber = indexPath.row;
UICollectionViewCell *cell;
switch (indexNumber) {
case 0:
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell1" forIndexPath:indexPath];
[cell.contentView addSubview:self.firstViewControllerObject.view];
break;
case 1:
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell2" forIndexPath:indexPath];
[cell.contentView addSubview:self.secondViewControllerObject.view];
break;
case 2:
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell3" forIndexPath:indexPath];
[cell.contentView addSubview:self.thirdViewControllerObject.view];
break;
default:
break;
}
return cell;
}
I could not figure out a way to manage cells better thus I made different entities. How can I do it better with this approach or if this approach is not good what should I use?
Upvotes: 9
Views: 9408
Reputation: 245
Actually for iOS, implement the native component like segmented control would be a better approach rather than trying to implement like what native android has to offer.
But if you really wanna try a viewpager like android, i think you can try using this library here. I tried implemented it myself and looks great. Hope it helps.
Upvotes: 4