【问题标题】:Need Help Setting Cell's TextLabel From NSDictionary需要帮助从 NSDictionary 设置单元格的 TextLabel
【发布时间】:2011-09-13 03:29:47
【问题描述】:

所以我有一个 NSDictionary,里面有 4 个对象。这些对象中的每一个都有 2 个属性,namedate

我可以通过记录列出所有数据。

【问题讨论】:

    标签: iphone objective-c xcode uitableview nsdictionary


    【解决方案1】:

    我假设您的示例代码在此方法中:

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

    如果不是,那是你的第一个问题。

    现在,您可能正在按顺序将每个单元格设置为一个一个每个标题,直到它到达列表的末尾。所有单元格都具有相同的标题,因为它们都具有列表中的最后一个标题。

    您应该放弃 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多