Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will need to create some sort of UITableView data source. Having the UITableView handle this is much more difficult than simply setting up a data structure and then pass that data in to the UITableView data source.</p> <p>A NSMutableArray would work just fine for what you need done. Whatever JSON parser toolkit you are using, you are likely given an arrayed response, which looks like is stored in headlinesArray, each containing the example code above.</p> <p>You simply need to enumerate through headlinesArray and IF the [post objectForKey:@"premium"] == TRUE then add it to the NSMutableArray.</p> <p>Place all of this in the viewDidLoad so that it is processed before the UITableView is built and then in the TableView you simply need to access that newly built array.</p> <pre><code>.h @interface YourClass: YourClassSuperclass { NSMutableArray *a; } .m //In ViewDidLoad a = [NSMutableArray array]; //Allocs and Inits a new array. for (Feed *f in headlinesArray) //For all feeds in the headlines array. (f is the local var) { //check if premium == TRUE. If yes, add to a. } //Then in your data source methods you just use the array named 'a' - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"standardCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; Feed *feedLocal = [a objectAtIndex:indexPath.row]; //Replaced headlinesArray with a NSString *headlineText = [NSString stringWithFormat:@"%@", feedLocal.headline]; cell.textLabel.text = headlineText; return cell; } </code></pre>
 

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