【发布时间】:2013-12-06 17:37:50
【问题描述】:
如您所见,我创建了一个自定义 UICollectionViewCell,每个单元格的创建都没有任何问题,并且可以找到 xib,但屏幕上没有显示任何内容。
我已经连接了 ProgrammaCell 的 xib 中代表的两个数据源。这是我的代码....
我的 CollectionView 被称为“griglia”,并在 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;
}
【问题讨论】:
标签: ios uicollectionview