Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that you reinitialize jobsarray at the end of the forin loop.</p> <p>You didn't mean ?</p> <pre><code>NSArray* jobs = [json objectForKey:@"results"]; NSMutableArray *jobsTemp = [[NSMutableArray alloc] initWithCapacity:jobs.count]; for(NSDictionary *jobsInfo in jobs) { JobInfo *jobby = [[JobInfo alloc] init]; jobby.city = jobsInfo[@"city"]; jobby.company = jobsInfo[@"company"]; jobby.url = jobsInfo[@"url"]; jobby.title = jobsInfo[@"jobtitle"]; jobby.snippet = jobsInfo[@"snippet"]; jobby.state = jobsInfo[@"state"]; jobby.time = jobsInfo[@"date"]; [jobsTemp addObject:jobby]; } self.jobsArray = jobsTemp; //set @property (nonatomic, copy) NSArray *jobsArray; in the .h [self.tableView reloadData]; //optional only if the data is loaded after the view </code></pre> <p>In the cell for row method :</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } JobInfo *job = self.jobsArray[indexPath.row]; cell.textLabel.text = job.title; return cell; } </code></pre> <p>And don't forget :</p> <pre><code>-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.jobsArray.count; } </code></pre> <p>Update - an user suggested an edit : </p> <p>It's true that count isn't a NSArray property. But as Objective-C lets us use a shortcut notation for calling method with a dot, this code works. You have to know limitation of this : if you use a NSArray subclass with a count property with a custom getter this could have side effects <code>@property (nonatomic, strong, getter=myCustomCount) NSUInteger count</code>. As I think code readability is to me one of most important things I prefer to use dot notation. I think Apple SHOULD implement count as readonly property so I use it this way (but it's my point of view). So for those which don't agree with me just read <code>return [self.jobsArray count];</code> in the tableView:numberOfRowsInSection: method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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