title: I mixed static and dynamic UITableViewCells in my UITableView and got wrong values in numberOfRowsInSection
body: <p>In my <code>swift</code> ios app I have a <code>UITableView</code> - in story board I added there 3 cells. The first two are static ones and the 3rd one is dynamic, basically first two shows some information and the 3rd one (and the rest generated based on 3rd) show comments. I fetch comments as a json from my webserver.</p>
  
  <p>When json is empty I see cell no. 1 and no. 2 - that's fine. But when json has one value, I see only cell no. 1, I don't see either 2 or 3. When json has 2 comments - I see two static cells.
  When json has 3 comments, I see two static cells + 3rd comment. Basically I never see two first comments.</p>
  
  <p>The problem might be here - this is how I'm fetching comments from webservice:</p>
  
  <pre><code>@IBOutlet weak var myTableView: UITableView!
  var items = NSMutableArray()
  ....
  
  Alamofire.request(.GET, "\(serverURL)/comments/\(case_id)/comments/")
      .validate()
      .responseJSON { response in      
          switch response.result {
          case .Success:
              self.items.removeAllObjects()
              if let jsonData = response.result.value {
                  let data = JSON(jsonData)
                  if let responseDictionary = data.dictionary {
                      if let commentsArray = responseDictionary["comments"]?.array {
                          for commentObject in commentsArray {
                              if let singleComment = SingleComment.fromJSON(commentObject){
                                  self.items.addObject(singleComment)
                              }
                          }
                          self.myTableView.reloadData()
                      }
                  }
  
              }
              self.myTableView.reloadData()
  
          case .Failure(let error):
              print("SWITCH ERROR comments")
              print(error)
          }
  }
  </code></pre>
  
  <p>and my method <code>numberOfRowsInSection</code> looks as follows:</p>
  
  <pre><code>func tableView(tview: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      if self.items.count == 0{
          return 2
      } else {
          return self.items.count;
      }
  }
  </code></pre>
  
  <p>I thought the solution could be to just modify the return statement in else block above, so that it is <code>return self.items.count+2</code>, but that throws an error:</p>
  
  <blockquote>
    <p><strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 ..
    0]'</p>
  </blockquote>
  
  <p>what could I do in such situation?</p>
  
  <p>====== EDIT</p>
  
  <p>my <code>cellForRowAtIndexPath</code> is a longer method, but I trimmed it down for the most important stuff:</p>
  
  <pre><code>func tableView(myComments: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      if indexPath.row == 0 {
          let cell = myComments.dequeueReusableCellWithIdentifier("firstCell") as! FirstCell
          ...
              return cell  
          }
  
      else if indexPath.row == 1 {
          let cell = myComments.dequeueReusableCellWithIdentifier("cellStatic") as! SecondCell
          ...
              return cell
  
      } else {
          let cell = myComments.dequeueReusableCellWithIdentifier("cell") as! SingleCommentCell
          let comment:SingleComment =  self.items[indexPath.row] as! SingleComment
          ...
          return cell
      }
  
  }
  </code></pre>