gpt4 book ai didi

IOS 如何在 UITableView 中显示数组字典

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:25:28 26 4
gpt4 key购买 nike

现在我已经声明:

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 中显示这两个可变字符串。这意味着表格 View 中的每个单元格都显示代码:12345 和颜色:黄色。

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

- (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;
}

下面是我的 Storyboard的屏幕截图。 storyboard

最佳答案

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

-(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;
}

关于IOS 如何在 UITableView 中显示数组字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33663860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com