title: Failed to obtain a cell from its dataSource with custom cells
body: <p>Updated:  Apologies, had a copy / paste issue - code is now shown as it exists - with ALL of the returns...</p>
  
  <hr>
  
  <p>Generally, I can figure this out with all of the great existing examples. Happy to update with any other information you may need.</p>
  
  <p>Objective:<br>
  Create a UITableViewController which has 2 sections.  In the upper section, I want to display a custom-classed row which provides switch-based settings.  On the lower section, I want to provide a list of items to select - again, using a custom-class.</p>
  
  <p>All cells and links were created in the storyboard</p>
  
  <p>Problem:<br>
  It compiles fine, but during runtime it fails with:   </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (; layer = ; contentOffset: {0, -64}; contentSize: {375, 88}>) failed to obtain a cell from its dataSource ()'
    First throw call stack:</p>
  </blockquote>
  
  <p>What I have tried: </p>
  
  <ol>
  <li>Using breakpoints, I have watched it roll through numberOfSections, and numberOfRowsInSection.  </li>
  <li>I have tried to use a breakpoint to check the cell in cellForRowAtIndexPath, but the exception is thrown before the function is called. </li>
  <li>Broken, and re-connected links, checked identifiers, re-validated everything I know to do.  </li>
  </ol>
  
  <p>Classes and screen shots are as follows:</p>
  
  <hr>
  
  <h2>Class for cell with Switches</h2>
  
  <p><a href="https://i.stack.imgur.com/lcZeX.jpg" rel="nofollow noreferrer">CellWithSwitch</a></p>
  
  <pre><code>import UIKit
  
  class CellWithSwitchTableViewCell: UITableViewCell {    
      @IBOutlet weak var nameLabel: UILabel!
      @IBOutlet weak var nameSwitch: UISwitch!
  
      override func awakeFromNib() {
          super.awakeFromNib()
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
      }
  
  }
  </code></pre>
  
  <hr>
  
  <h2>Class for cells with selection</h2>
  
  <p><a href="https://i.stack.imgur.com/G6PB4.jpg" rel="nofollow noreferrer">CellWithSelect</a></p>
  
  <pre><code>import UIKit
  
  class CellWithSelectTableViewCell: UITableViewCell {
  
      @IBOutlet weak var nameLabel: UILabel!
  
      override func awakeFromNib() {
          super.awakeFromNib()
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
      }
  }
  </code></pre>
  
  <hr>
  
  <h2>TableViewController:</h2>
  
  <pre><code>class MapOptionsTableViewController: UITableViewController {
      var mapOptions = MapOptionsAvailable()
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          // return the number of sections
          return 2
      }
  
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          var returnValue = Int()
  
          if section == 1 {
              returnValue = 1  
  
          } else if section == 0 {
  
              returnValue =  1 
          }
          return returnValue
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          print("Entered cellforRowAtIndexPath.  Row",indexPath.row,"Section",indexPath.section)
  
          if indexPath.section == 0 {
              let cell = tableView.dequeueReusableCell(withIdentifier: "CellWithSwitch", for: indexPath as IndexPath) as! CellWithSwitchTableViewCell
              cell.nameLabel.text = "Name of switch"
              cell.nameSwitch.setOn(true, animated: true)
  
              return cell
  
          } else {
              let cell = tableView.dequeueReusableCell(withIdentifier: "CellWithSelect", for: indexPath as IndexPath) as! CellWithSelectTableViewCell
              cell.nameLabel.text = "Name of Selection"
  
              return cell
  
  
          }
      }
  }
  </code></pre>
  
  <p>Let me know if I can furnish any additional info.  </p>