Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A table view's controller doesn't "know without being told" anything-- it doesn't inherently have a property like you mention that data comes from. You supply that data, one cell at a time, generally in your view controller subclass.</p> <p>Typically your table view controller object is both the table view's delegate and the table view's data source delegate. From <a href="http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAPIOverview/TableViewAPIOverview.html" rel="nofollow noreferrer">the Apple docs</a>:</p> <blockquote> <p>A UITableView object must have a delegate and a data source. Following the Model-View-Controller design pattern, the data source mediates between the application’s data model (that is, its model objects) and the table view; the delegate, on the other hand, manages the appearance and behavior of the table view. <strong>The data source and the delegate are often (but not necessarily) the same object, and that object is frequently a custom subclass of UITableViewController.</strong></p> </blockquote> <p>The table view doesn't take in an array or dictionary and pull data from it; it asks you in your data source what each cell should look like. You just implement this method:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>And return whatever contents in a cell that you want for the row you're being asked about. You can put logic in there to mix/match/pull data from wherever you want.</p> <p>Could your confusion come from a soup of sample code maybe that's unclear about what's going on? I'd recommend building a table view from scratch to see how this works-- it's easy to do this by adding a new class to your project, you can select a UITableViewController subclass from inside XCode in the "new" wizard. It will prepopulate the .m file with all the relevant empty methods, including the above.</p> <hr> <p>EDIT: Don't change the table view your view controller owns when doing a search. You're confusing the instance reference called "tableView", which your view controller owns, with the argument to the delegate method <code>tableView:cellForRowAtIndexPath:</code>, which is just getting passed in to tell you <em>which</em> table view is asking for a cell. When you have search set up in the normal way with the same viewcontroller being the delegate for both the default/content table and the search results, you could get called with either. <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchDisplayController_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UISearchDisplayController" rel="nofollow noreferrer">See here for the docs on this</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload