更新用户详细信息并将其与用户详细信息一起保存到现有字典中

Update User Details and save it into existing dictionary with user details

我在 ViewControllerA 上有一个字典,我正在通过 Segue.The 将该字典传递给 ViewController B detailsDictionary 包含如下用户详细信息:

{
    City = abc;
    Country = Indi;
    DOB = "12/3/2016 12:00:00 AM";
    EmailID = "abc@gmail.com";
    FName = dhruv;
    LName = kumar;
    MName = Singh;
    Password = "";
    State = Chandigarh;
    UserID = "f2266e5d-c709-42fb-ad98-b75873ac2fd1";
}

现在在 View Controller B 上有用户可以更新其详细信息的 texfield,post server.I 的更新详细信息使用了以下代码

 -(void)textFieldDidEndEditing:(UITextField *)textField
    {
        NSInteger field = textField.tag;
        NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"fname"];

        }
        if(field ==2)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"mname"];


        }

        if(field ==3)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"lname"];
        }

        if(field ==4)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"city"];
        }

        if(field ==5)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"state"];
        }

        if(field ==6)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"country"];
        }

        if(field ==7)
        { 
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"dob"];
        }  
    }

我希望如果用户更新他们的详细信息,那么新更新的详细信息将保存在 detailsDictionary 中,否则如果用户不进行任何更改,detailsDictionary 将保留以前的 details.But,我无法实现 this.I 我不明白如何检查字典中的新细节并在有新细节的情况下更改值或在没有 change.Kindly 帮助的情况下保留旧值,在此先感谢!

您做的是正确的,只是您需要确保密钥与用户正在更新的密钥相同,因为密钥区分大小写,因此您需要确保您将使用与代码中相同的密钥您使用的是小写字母,而键中包含一些大写字母

-(void)textFieldDidEndEditing:(UITextField *)textField
    {
        NSInteger field = textField.tag;
        if(field ==1)
        {

        NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"FName"];

        }
        if(field ==2)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"MName"];


        }

        if(field ==3)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"LName"];
        }

        if(field ==4)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"City"];
        }

        if(field ==5)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"State"];
        }

        if(field ==6)
        {
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"Country"];
        }

        if(field ==7)
        { 
            NSLog(@"cell1.userDetailTextField.text %@",textField.text);
            [_detailsDictionary setObject:textField.text forKey:@"DOB"];
        }  
    }