title: How does data source and delegate in UITableView works?
body: <p>I am new in ios development. When I use UITableView, I implement data source and delegate together. like the following two methods: </p>
  
  <pre><code> // Data source method
   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  
   // Delegate method
   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
  </code></pre>
  
  <p>However, if I am understand correctly, table view does not hold any data, and it only store enough data to draw the rows that are currently visible. Therefore, for instance, if I have 10 data in table, and only shows 5 currently. That means delegate method runs 5 times, but before delegate method runs 5 times, data source method already runs 10 times to get the number of rows. And the reason we use data source is to manage the content that presents using a collection view. So my question is, how does data source manage the content? Does data source object store all of those table view information?(since it runs before delegate and it knows the total numbers of table view) If it stores information of table view, it seems conflict with delegate since table view delegate does not hold any data, right? </p>
  
  <p>One more question is in what situation we just use data source? because we can create custom delegate right? Is there situation we only create custom data source? Since I've seen data source always comes with delegate.... Thanks!!!</p>