title: Reload model for UITableViewController before [tableview reloadData]
body: <p>This is my first try into iPhone development and I have some <code>UITableViewController</code>s which will show the data returned from a webservice.</p>
  
  <p>In my AppDelegate I have setup a timer which is called every few seconds and reloads the model. I keep the same object reference and just refresh it's contents, so I have the same object on any <code>UITableViewController</code> that is visible at the moment.</p>
  
  <p>When the data is refreshed on the AppDelegate, I call:</p>
  
  <pre><code>[[(UITableViewController *)[self.navigationController topViewController] tableView] reloadData];
  </code></pre>
  
  <p>The model is basically a collection of <code>file</code> objects. Each <code>file</code> object has some properties and flags.</p>
  
  <p>This works quite well if the current <code>UITableViewController</code> is a simple table, with one section, that maps each cell to a sequential index on the Array of <code>files</code>.</p>
  
  <p>But I have one of the <code>UITableViewController</code>s that shows this <code>file</code> details and, depending on a flag on the <code>file</code> object, will show 2 or 3 sections. I've put this logic here:</p>
  
  <pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      if ([[_file status] intValue] &amp; DOWNLOADING) {
          kIndexTransferSpeed = 1;
          kIndexSettings = 2;
          return 3;
      } else {
          kIndexSettings = 1;
          kIndexTransferSpeed = -1;
          return 2;   
      }
  }
  </code></pre>
  
  <p>So on this controller, my <code>-tableView:cellForRowAtIndexPath:</code> is just a big <code>if</code> statement that will show a property from the <code>_file</code> object, depending on the <code>indexPath</code>.</p>
  
  <p>The problem with this approach is that when this table is reloading on the device, I can actually see it being reloaded. The section titles flash for a moment and the cells take a bit to show up. Specially if I am scrolling the table while it's reloaded.</p>
  
  <p>I've read somewhere that I should keep myself from putting any logic on those <code>UITableViewController</code> methods. But what should I do?</p>
  
  <p>I thought about having a specific method that will create a "data view model" with the data ready to be consumed by <code>- tableView:cellForRowAtIndexPath:</code> and would be called by the AppDelegate before calling it's [tableView reloadData]. But I'd have to recreate this whole "view model" everytime it's called, since it's the same object and I don't really know what has been changed on the data model.</p>