简体   繁体   English

需要帮助从NSDictionary设置单元格的TextLabel

[英]Need Help Setting Cell's TextLabel From NSDictionary

So I have an NSDictionary with 4 objects in it. 所以我有一个NSDictionary,里面有4个对象。 Each of these objects then has 2 properties, name and date 每个对象都具有2个属性,即namedate

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: 您应该删除for循环并改用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM