【发布时间】:2016-03-30 19:18:38
【问题描述】:
我有 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;
}
【问题讨论】:
-
不清楚你的实际问题是什么,但我可以告诉你,当表格视图滚动和单元格被重用时,根据单元格的内容做出决定会给你带来问题;您应该根据数据模型的内容做出决定。
-
我希望“选择元素”不会被选中
-
一种方法是在
didSelectRowAtIndexPath中,如果它是第一行/空行,您只需取消选择该行
标签: ios objective-c json uitableview dictionary