Jon
Jon

Reputation: 4732

Need Help Setting Cell's TextLabel From NSDictionary

So I have an NSDictionary with 4 objects in it. Each of these objects then has 2 properties, name and date

I can list out all the data by logging it.

Upvotes: 1

Views: 411

Answers (1)

Matthew Gillingham
Matthew Gillingham

Reputation: 3429

I am assuming your sample code is inside of this method:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

If not, that is your first problem.

Right now, you are probably sequentially setting each cell to have every title one by one, until it gets to the end of the list. All of the cells have the same title because they all have the last title in the list.

You should drop the for-loop and use this instead:

NSDictionary *object = [objects objectAtIndex:[indexPath row]];
NSString *title = [object objectForKey:@"title"];
NSString *date = [object objectForKey:@"publishedDate"];
cell.textLabel.text  = title;
cell.detailTextLabel.text  = date;

Upvotes: 1

Related Questions