title: UITableView and its cell in a xib file
body: <p>Long story short, I want to create a XIB file, where it contains:</p>
  
  <ol>
  <li><p>A view. In that view, it has many things and a tableView. (connected data source, delegate to file's owner). That view is the main view of the XIB files.</p></li>
  <li><p>Custom cell, (use as the prototype cell of tableView, since XIB doesn't support prototype tableView).</p></li>
  </ol>
  
  <p>How could I achieve both of these? <strong>Also, I want to know the same apply to UICollectionView.</strong></p>
  
  <p>I had created both of those, load it to the main view (the main view is in the main storyboard). But the tableView doesn't load the custom cell as expected. The cell is just blank, doesn't look like what it's designed in the nib.</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here's how I register the nib to the main view in storyboard:</p>
  
  <pre><code>- (UIView *)buildViewFromViewControllerClass:(Class)viewControllerClass
  {
      id viewController = [[viewControllerClass alloc] initWithNibName:NSStringFromClass(viewControllerClass) bundle:nil];
      [viewController view].frame = self.containerView.bounds;
  
      [self addChildViewController:viewController];
  
      return [viewController view];
  }
  </code></pre>
  
  <p>I have many viewControllers, so I figure out that this is the best way to add VC.</p>
  
  <p>About the nib in description above, I just use regular initialization:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      // init cell
      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
      if (!cell) {
          cell = [[PaymentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"];
      }
  
      return cell;
  }
  </code></pre>
  
  <p>If in the view did load method, I register the nib to the tableView, it'll crash in <code>[tableView dequeueResuableCell...]</code>. The registered code:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
  //    [self.tableView registerNib:[UINib nibWithNibName:self.nibName bundle:nil]
  //                forCellReuseIdentifier:@"CustomCell"];
  // I'm commenting it, because it caused crash.
  }
  </code></pre>
  
  <p>Crash message:</p>
  
  <blockquote>
    <p>*** Terminating app due to uncaught exception
    'NSUnknownKeyException', reason: '[
    setValue:forUndefinedKey:]: this class is not key value
    coding-compliant for the key tableView.'</p>
  </blockquote>
  
  <p>What did I do wrong here?
  Here's a picture how I designed the nib:</p>
  
  <p><img src="https://i.stack.imgur.com/dJzr0.png" alt="Model"></p>
  
  <p>As you can see, the file's owner's mainView is connected to the <code>mainView</code>, where it contain the tableView. The customCell is just a custom designed cell, define in the same file (the .m file).</p>