UICollectionView不显示任何单元格

时间:2014-11-10 18:00:33

标签: ios objective-c xcode uicollectionview

我已经尝试了所有的东西来让细胞变得更复杂,甚至重新做一些教程和堆栈的其他问题,但并不成功。我需要帮助,这是我的代码:

我在XCode 6中使用以下代码与故事板和iOS 8.一切都设置正确,如标签等。

#import "LMSceneCollectionViewController.h"

@interface LMSceneCollectionViewController () {
    NSArray *sceneIcons;
}

@end

@implementation LMSceneCollectionViewController

static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;

    // Register cell classes
    [self.collectionView registerClass:[LMSceneCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

    // Do any additional setup after loading the view.
    sceneIcons = [[NSArray alloc] init];
    sceneIcons = [NSArray arrayWithObjects:@"Cenario_Desligar.png", @"Cenario_Manhã.png", @"Cenario_Tarde.png", @"Cenario_Noite.png", @"Cenario_Filme.png", @"Cenario_Festa.png", @"Cenario_Romântico.png", @"Cenario_Plus.png", nil];

}

- (void)viewWillAppear:(BOOL)animated{
    [self.collectionView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return sceneIcons.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LMSceneCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    // Configure the cell
//    UIImageView *sceneImageView = (UIImageView *) [cell viewWithTag:100];
//    sceneImageView.image = [UIImage imageNamed:[sceneIcons objectAtIndex:indexPath.row]];
//    cell.alpha=1.0f;
    cell.imageScene = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[sceneIcons objectAtIndex:indexPath.row]]];
    cell.textScene.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row];

    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {

}
*/

@end

0 个答案:

没有答案