gpt4 book ai didi

ios - 如何使用json字典,让key为空value不select?

转载 作者:行者123 更新时间:2023-11-29 12:07:43 24 4
gpt4 key购买 nike

我有 NSDictionary 元素和我正在表上显示的这本字典,如果从这些将显示在文本字段上的 dict 中选择任何元素,我正在做什么。

dict :{
"" = "Select Elements";
1 = lengha;
2 = Choli;
3 = Pyjami;
4 = Dupatta;
5 = Salwar;
6 = Yoke;
8 = Body;
}

现在我必须处理这个问题,如果键为空,则不会在文本字段上选择值。即“选择元素”不会在文本字段上选择,或者如果它被选中,则数据将不会保存并显示一些保存消息。

  UITableViewCell *selectedCell = [itemTable cellForRowAtIndexPath:indexPath];
NSString *elemCell = selectedCell.textLabel.text;
NSMutableArray *arrayElements = Nil;
if([elementsField.text isEqualToString:@""])
{
arrayElements = [NSMutableArray new];

}
else
{
arrayElements = [[elementsField.text componentsSeparatedByString:@","]mutableCopy];

}
if ([arrayElements containsObject: elemCell])
{
[arrayElements removeObject:elemCell];
}
else
{
[arrayElements addObject: elemCell];

}
NSString *str = [arrayElements componentsJoinedByString:@","];

elementsField.text = @"";
elementsField.text = str;
[itemTable deselectRowAtIndexPath:indexPath animated:YES];
itemTable.hidden = YES;

}

最佳答案

该 JSON 数据定义错误,应如下所示:

choices : {
"title" = "Select Elements",
"elements" = [
"lengha",
"Choli",
"Pyjami",
"Dupatta",
"Salwar",
"Yoke",
"Body"
]
}

这将解决您的问题。

关于ios - 如何使用json字典,让key为空value不select?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451198/

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