【问题标题】:IOS how to display dictionary of arrays in UITableViewIOS如何在UITableView中显示数组字典
【发布时间】:2016-02-13 07:54:54
【问题描述】:

现在我已经声明:

NSMutableArray *feeds;
NSMutableString* Severity;
NSMutableString* incidentNumber;
NSMutableDictionary *IncidentGetList;

我已经成功从 XMLParser 中检索出数据,日志中的数据是这样的:

Final Feed : (
        {
        code = 80180058;
        Severity = Warning;
    },
        {
        code = 80167359;
        color = red;
    },
        {
        code = 80143253;
        color = green;
    },
        {
        code = 80118575;
        color = blue;
    },
        {
        code = 80114765;
        color = yellow;
    }
)

问题是如何在 ONE CELL 中显示这两个可变字符串。这意味着表格视图中的每个单元格都显示代码:12345 和颜色:黄色。

下面是我在表格视图中的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [feeds count];
}


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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

        cell.textLabel.text = [[feeds objectAtIndex:indexPath.row]objectForKey:@"color"];
             cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey:@"code"];
        return cell;
}

下面是我的故事板的屏幕截图。

【问题讨论】:

  • 你现在做了什么? 1 个标签:代码?
  • 我无法将字典提要中的数据显示到表格视图中。
  • 我的字典包含两个可变字符串严重性和事件编号。我希望两个字符串都显示在表格视图的一个单元格中
  • 现在什么都没有显示?

标签: ios objective-c arrays dictionary tableview


【解决方案1】:

您可以将这两个值组合成一个字符串然后显示。例如:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

     cell.textLabel.text = [NSString stringWithFormat:@"Code : %@ , Color : %@",[[feeds objectAtIndex:indexPath.row] objectForKey:@"code"],[[feeds objectAtIndex:indexPath.row]objectForKey:@"color"] ];
     return cell;
}

【讨论】:

  • 我还是不能把东西显示出来。
  • UITableViewCell 中当前显示什么?
  • 您是否检查了 UITableView 的委托和数据源的连接?因为你的其他方法看起来不错。
  • 如何检查连接?你要我提供什么信息?对不起。
  • 你是如何分配 UITableView 的?如果您使用过情节提要,请检查您是否已将数据源和委托分配给您的 viewController 。如果以编程方式检查 testTableView.delegate = self;和 testTableView.datasource = self;存在线条
猜你喜欢
  • 2015-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多