UICollectionViewController is invalidly loaded with NIB

iOS 6.0 testing on iPhone 5

I am loading a subclass UICollectionViewControllerfrom nib. When I heat up the method awakeFromNib, it claims that the view is loaded. The call collectionViewreturns nil.

Therefore, I have a problem with registering an element that should load my cells.

- (void)awakeFromNib {
  if ([self isViewLoaded])
    NSLog(@"[%@ %@] registered with %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd),
          self.collectionView);

  UINib *nib = [UINib nibWithNibName:@"MyCollectionCell" bundle:nil];
  [self.collectionView registerNib:nib forCellWithReuseIdentifier:NIB_ID];
}

Output above:

2012-09-22 19:21:49.129 myApp[7182:907] [MyCollectionViewController awakeFromNib] registered with (null)

In addition, loadViewand viewDidLoadnot caused by (expected when downloading from Niba).

When I try to load cells, I lose with an error.

Current workaround redundantly registering nib in collectionView:cellForItemAtIndexPath::

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  UINib *nib = [UINib nibWithNibName:@"MyCollectionCell" bundle:nil];
  [collectionView registerNib:nib forCellWithReuseIdentifier:NIB_ID];

Questions: Have you encountered this? Do you see the error of my ways? Is this a known bug?


Edit : more information ...

awakeFromNib, collectionView

(lldb) po [self view]
(UIView *) $1 = 0x1f158400 <UICollectionView: 0x1f158400; frame = (0 0; 320 548); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x1ed8fcf0>; layer = <CALayer: 0x1ed8f790>; contentOffset: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x1ed919a0>
(lldb) po [self collectionView]
(UICollectionView *) $2 = 0x00000000 <nil>

wakeFromNib view collectionView :

  [(UICollectionView *)self.view registerNib:nib forCellWithReuseIdentifier:NIB_ID];
+5
1

. iOS , - . , .

'self.view', UIViewController 'view' , . ( viewDidLoad.)

viewDidLoad , UINib.

+2

All Articles