I have created a custom xib and my aim is to display it like the image below in a collection view:
I set up my collection view like this:
Collection View Title
+(id)newTitleView
{
VideoCollectionViewTitleView* vidcollectionTitleView = [[[NSBundle mainBundle] loadNibNamed:@"ProductCollectionViewTitleView" owner:nil options:nil] lastObject];
if ([vidcollectionTitleView isKindOfClass:[VideoCollectionViewTitleView class]])
{
return vidcollectionTitleView;
}
else
{
return nil;
}
}
Data Source
-(instancetype)initWithVideos:(Videos *)videos
{
self = [super init];
if (self)
{
_videos = videos;
}
return self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _videos.content.count ;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Video *video = [self.videos content][indexPath.row];
VideoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kGENERIC_COLLECTION_CELL_ID forIndexPath:indexPath];
for (int cnt = 0; cnt <[[video youtube]count]; cnt++) {
NSMutableString *youtubeImageString = [[NSMutableString alloc]initWithString:kYOUTUBE_IMAGE_URL];
[youtubeImageString replaceOccurrencesOfString:@"videoId" withString: [video youtube][cnt++] options:0 range:NSMakeRange(0, youtubeImageString.length-1)];
NSLog(@"check the url %@", youtubeImageString);
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:youtubeImageString]
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (cacheType != SDImageCacheTypeMemory)
{
cell.imageView.alpha = 0.0;
double val = ((double)arc4random()/ARC4RANDOM_MAX)*0.8;
[UIView animateWithDuration:0.2 delay:val options:UIViewAnimationOptionCurveEaseInOut animations:^{
cell.imageView.alpha = 1.0;
} completion:nil];
}
}];
//set labels
[cell.nameLabel setText:@"Videoooos"];
}
return cell;
}
This is how I add the objects to the data source:
VideoCollectionViewTitleViewDataSource *dataSource = [[VideoCollectionViewTitleViewDataSource alloc]initWithVideos:self.model.videos];
[self.collectionViewDataSourceArray addObject:dataSource];
And this is the result that I am getting:
When I put a break point on : [self.collectionViewDataSourceArray addObject:dataSource];
this is what I am getting:
As you can see there is only item but there are more than one item in my array, any suggestions on what I am doing wrong here would be really appreciated as I am stuck on this.
Video.Content[ ]Youtube[ ] :
[type]: videos [content]: ( " \n [youtube]: (\n 4Cw856cbyNI,\n GcmEqI9fpYo,\n L7xR42O825Q,\n kZem01RQOeQ,\n
L7xR42O825Q,\n \"swgU9Q-8aEA\",\n \"v_joMRl6wus\",\n
tKwSgFo0Dz8,\n \"Rg2C-9QJmN0\",\n \"UEW3EYc_aKE\"\n
)\n" )
Videos Class:
@interface Videos : JSONModel
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *type;
@property (strong, nonatomic) NSString *display;
@property (strong, nonatomic) NSArray <Video> *content;
Video Class
#import <Foundation/Foundation.h>
#import "JSONModel.h"
@protocol Video @end
@interface Video : JSONModel
@property (strong, nonatomic) NSArray *youtube;
@end
Note : I have already looked at : Link 1, however it is not useful in my case.