user5408951
user5408951

Reputation:

How to use json dictionary, so that is the key is blank then value will not select?

I am having the NSDictionary elements and this dictionary i am showing on the table, what i am doing that if any element is selected of these dict that will display on the textfield.

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

Now i have to do with this that if the key is blank then value will not select on the textfield.i.e "Select Elements" this will not select on the textfield or if it is selected then data will not save and show some meassage on saving.

  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;

    }

Upvotes: 1

Views: 51

Answers (1)

trojanfoe
trojanfoe

Reputation: 122391

That JSON data is misdefined and should look like:

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

and that will solve your problem.

Upvotes: 1

Related Questions