开发者

Need Help Setting Cell's TextLabel From NSDictionary

开发者 https://www.devze.com 2023-04-04 05:11 出处:网络
So I have an NSDictionary with 4 objects开发者_开发技巧 in it.Each of these objects then has 2 properties, name and date

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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消