IOS 如何在 UITableView 中显示数组字典
IOS how to display dictionary of arrays in UITableView
现在我已经声明:
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 中显示这两个 Mutable 字符串。这意味着 table 视图中的每个单元格都显示代码:12345 和颜色:黄色。
下面是我在 table 视图中的代码:
- (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;
}
下面是我的故事板的屏幕截图。
您可以将这两个值组合成一个字符串,然后显示。例如:
-(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;
}
现在我已经声明:
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 中显示这两个 Mutable 字符串。这意味着 table 视图中的每个单元格都显示代码:12345 和颜色:黄色。
下面是我在 table 视图中的代码:
- (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;
}
下面是我的故事板的屏幕截图。
您可以将这两个值组合成一个字符串,然后显示。例如:
-(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;
}