I am pretty new to ios, objective-c and xcode. Trying to learn by building a simple app using collection view. I am not sure I got the outlet and file owner's set and linked properly.
I am getting following error:
2015-01-16 08:15:19.711 test[4548:187055] * Assertion failure in -[ViewController loadView], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UICollectionViewController.m:166 2015-01-16 08:15:19.713 test[4548:187055] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] loaded the "tzI-IH-vJx-view-Jhf-9m-MoA" nib but didn't get a UICollectionView.'
I have a storyboard. It has a View Controller. Within the View Controller, I have a View. Within this View, I have Collection View. Within this Collection View, I have CollectionViewCell. Within CollectionViewCell, I have Image View. I am not sure how these should be connected.
Here is my code and I can't put up a screen shot, I just joined. Can someone help. This should be easy but I spent quite of bit of time.
Thanks
==========================
ViewController.m:
#import "ViewController.h"
#import "Cell.h"
@interface ViewController (){
NSArray *myArray;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
===============================
ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, weak) IBOutlet UICollectionView *collectionView;
@end
==============================
Cell.h:
#import <UIKit/UIKit.h>
@interface Cell : UICollectionViewCell
@property (nonatomic, weak) IBOutlet UIImageView *itemImageView;
@end
=============================
Cell.m:
#import "Cell.h"
@implementation Cell
@end
If you associated your ViewController
class with the view controller object in the storyboard, then what you should ensure is that the view
binding for ViewController
is set properly to the collectionView
object. I hope the image below will make clearer what you should check:
You will also notice the 2 bindings dataSource and delegate: make sure that the collectionView
dataSource
and delegate
bindings are bound to the view controller.
On another coin, I do not know what you are trying to do, but you could find it easier to instantiate a UICollectionViewController
in the storyboard. That will give you all of the above already nicely set up. (Unless you are trying to have a collection view that only takes a part of the screen.)