title: Can't assign delegate methods to UIViews?
body: <p>I defined a simple CollectionView view,</p>
  
  <p>When I place the delegate methods in a ViewController, the cells are displayed correctly. However, when I moved it to a UIView, none of the delegate methods are called.</p>
  
  <p>Anyone knows why? Attached the code.</p>
  
  <p>In the ViewController, <code>viewDidLoad</code> method,</p>
  
  <pre><code>self.userGrid = [[UserGrid alloc] initWithFrame:self.view.frame];
  </code></pre>
  
  <p>UserGrid.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "AvatarViewCell.h"
  #import "GridViewLayout.h"
  
  @interface UserGrid : UIView &lt;UICollectionViewDelegate, UICollectionViewDataSource&gt;
  
  @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  
  @end
  </code></pre>
  
  <p>And UserGrid.m</p>
  
  <pre><code>#import "UserGrid.h"
  
  @implementation UserGrid
  
  - (id)initWithFrame:(CGRect)aRect
  {
      UINib *cellNib = [UINib nibWithNibName:@"AvatarViewCell" bundle:nil];
      [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"avatarCell"];
  
      if ((self = [super initWithFrame:aRect])) {
          self.collectionView.dataSource = self;
          self.collectionView.delegate   = self;
  
          [self.collectionView registerClass:[AvatarViewCell class] forCellWithReuseIdentifier:@"avatarCell"];
      }
      return self;
  }
  
  - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  {
      return 12;
  }
  
  - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  {
      return 1;
  }
  
  - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *identifier = @"avatarCell";
  
      AvatarViewCell *avatarCell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
      [avatarCell.avatarImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"website_%ld.jpg", indexPath.row + 1]]];
  
      return avatarCell;
  }
  
  @end
  </code></pre>
  
  <p>** EDIT</p>
  
  <p>I changed the init part to (in viewDidLoad),</p>
  
  <pre><code>self.userGrid = [[[NSBundle mainBundle] loadNibNamed:@"UserGrid" owner:nil options:nil] lastObject];
  self.userGrid.frame = self.view.frame;
  </code></pre>
  
  <p>Added in viewDidAppear,</p>
  
  <pre><code>- (void)viewDidAppear:(BOOL)animated {
      [self.userGrid.collectionView reloadData];
  }
  </code></pre>
  
  <p>Added awakeFromNib method, but delegate methods are not called ... hmm</p>
  
  <pre><code>- (void)awakeFromNib {
      UINib *cellNib = [UINib nibWithNibName:@"AvatarViewCell" bundle:nil];
      [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"avatarCell"];
  
      NSLog(@"awake");
      self.collectionView.dataSource = self;
      self.collectionView.delegate   = self;
  
      [self.collectionView registerClass:[AvatarViewCell class] forCellWithReuseIdentifier:@"avatarCell"];
  }
  </code></pre>