I am trying to build a uiCollectionView which pages horizontally per data section - the App is for personal trainers and each section is an exercise which has a number of dynamic attributes (speed, km's, time etc).
I have created a custom cell for the attributes and i'm simply at the stage of trying to apply the custom cell to view view, populating a title and adding the scrolling - here is my code -
- (void)loadView
{
//self.prefs = [NSUserDefaults standardUserDefaults];
//self.collectionView.backgroundView = [[UIImageView alloc] initWithImage:
// [UIImage imageNamed:[self.prefs stringForKey:@"BGImageBlah"]]];
self.view = [[UIView alloc]
initWithFrame:[[UIScreen mainScreen] bounds]
];
// Create a flow layout for the collection view that scrolls
// horizontally and has no space between items
UICollectionViewFlowLayout *flowLayout = [
[UICollectionViewFlowLayout alloc] init
];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.minimumLineSpacing = 5;
flowLayout.minimumInteritemSpacing = 0;
// Set up the collection view with no scrollbars, paging enabled
// and the delegate and data source set to this view controller
self.collectionView = [[UICollectionView alloc]
initWithFrame:self.view.frame
collectionViewLayout:flowLayout
];
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.pagingEnabled = YES;
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.view addSubview:self.collectionView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return 9;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Dequeue a prototype cell and set the label to indicate the page
WOColView *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:@"CellWO"
forIndexPath:indexPath
];
cell.titleLbl.text = @"yo";
// Switch colors to see view swipes... DELETE
CGFloat hue = (CGFloat)indexPath.row / 9;
cell.backgroundColor = [UIColor
colorWithHue:hue saturation:1.0f brightness:0.5f alpha:1.0f
];
cell.titleLbl.textColor = [UIColor whiteColor];
cell.titleLbl.tintColor = [UIColor whiteColor];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return collectionView.bounds.size;
}
this is a screenshot of my storyboard and connections -
This compiles ok but all i get is an empty full screen of color - which does scroll - but theres no evidence of anything else in my custom cell!? Where am I going wrong.