Ahad Porkar
Ahad Porkar

Reputation: 1698

Nothing apear in UIcollectionView Controller

I have UIcollectionView in my first view of application after Uinavigationviewcontroller just in storyboard just like this :

enter image description here

this is my RootViewController.h

#import <UIKit/UIKit.h>
@interface RootViewController : UICollectionViewController<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *entries;
 @end

and my RootViewController.m :

#import "RootViewController.h"
#import "AppRecord.h"
#import "Cell.h"
#define kCustomRowCount     7


@interface RootViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
// the set of IconDownloader objects for each app
@property (nonatomic, strong) NSMutableDictionary *imageDownloadsInProgress;
@end


@implementation RootViewController

#pragma mark 

// -------------------------------------------------------------------------------
//  viewDidLoad
// -------------------------------------------------------------------------------
- (void)viewDidLoad
{
 NSLog(@"inside class");
    [super viewDidLoad];
   // self.title = @"My Title";

    //self.collectionView.delegate = self;
    //self.collectionView.dataSource=self;

}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    NSUInteger count = [self.entries count];
    NSLog(@"count: %lu", (unsigned long)count);

    if (count == 0)
    {
        return kCustomRowCount;
    }
    return count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"inside cell");
    AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
    Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
    UIImage *truckImage = [[UIImage alloc] init];
    truckImage = [UIImage imageNamed:@"Default.png"];
    cell.imageView.image = truckImage;
    return cell;
}

@end

now problem is none of my "cellForItemAtIndexPath" or "numberOfItemsInSection" or even "viewDidLoad" getting called and the output on Simulator is black screen.

This is my reload section of AppDelegate class :

    __block ParseOperation *weakParser = parser;

    parser.completionBlock = ^(void) {
        if (weakParser.appRecordList) {
            dispatch_async(dispatch_get_main_queue(), ^{
                RootViewController *rootViewController = (RootViewController*)[(UINavigationController*)self.window.rootViewController topViewController];

                rootViewController.entries = weakParser.appRecordList;
                if(weakParser.appRecordList != nil)
                    NSLog(@"weakParser.appRecordList is Not nill");
                [rootViewController.collectionView reloadItemsAtIndexPaths:[rootViewController.collectionView indexPathsForVisibleItems]];
                [rootViewController.collectionView reloadData];
            });
        }

        self.queue = nil;
    };

    [self.queue addOperation:parser];
    self.appListData = nil;
}

Upvotes: 0

Views: 261

Answers (2)

wootage
wootage

Reputation: 936

Do you have identifier on the storyboard cell?You can try to add

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MY_CELL"];

in viewDidLoad

Since your RootViewController inherit UICollectionViewController you don't need to add UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout at all

Upvotes: 1

Stefano Mondino
Stefano Mondino

Reputation: 1219

Did you add the delegate and datasource connection for the collection view? It's the most common mistake, usually. They're commented out in code, I assume you did that via Storyboard

Upvotes: 2

Related Questions