I created a custom UICollectionViewCell as you can see, the creation of every single cell without any problems and can find the xib, but nothing is displayed on the screen.
I have connected both the datasource that the delegates in the xib of ProgrammaCell. Here is my code ....
my CollectionView is called "griglia" and is connected in the xib
@interface GrigliaProgrammiViewController : UIViewController <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{ XMLParser *xmlParser;
}
....
@end
- (void)viewDidLoad
{
[super viewDidLoad];
.....
[self.griglia registerClass:[ProgrammaCell class] forCellWithReuseIdentifier:@"prg"];
self.griglia.dataSource = self;
self.griglia.delegate = self;
xmlParser = [[XMLParser alloc]
loadXMLByURL:@"..."];
[self.griglia reloadInputViews];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section {
return [[xmlParser programmi] count];}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
ProgrammaCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"prg" forIndexPath:indexPath];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Programma" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
Programmi *programma = [[xmlParser programmi] objectAtIndex:indexPath.row];
cell.titolo.text= programma.titolo;
cell.giorno.text = programma.programma_giorno;
cell.orario.text = programma.programma_orario;
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = cell.immagine.bounds;
[cell.immagine addSubview:activityIndicator];
[cell.immagine setImageWithURL:[NSURL URLWithString:programma.programma_copertina]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[activityIndicator removeFromSuperview];
}];
return cell;
}