Reputation: 2777
I am making a form in objective-c. I post all the data that I filled in, in my form to a webservice. This gives me a 200-code if everything is OK and the data is posted successfully. But it gives me a 406-code if there is something wrong. If that is the case. The JSON also contains error objects. You can see an example of the JSON over here.
{
"data": {
"status": 406,
"message": "Not Acceptable",
"errors": {
"cu_email": [
"'stefappmax.be'is no valid email!"
]
}
}
}
Al my textfields have the same name as in the JSON e.g. My email-textfield calls cu_email
Now I have this piece of code.
NSDictionary* dict = [json objectForKey:@"data"];
NSLog(@"dict: %@",dict);
for (NSString *errorObject in [dict objectForKey:@"errors"]) {
NSLog(@"error name: %@",errorObject);
}
This gives back all the names of the textfields that contains an error. What I want to do now is to make a red border around those textfields. I know to place a border you need to implement the quartzcore frame work and add this piece of code.
self.cu_email.layer.borderColor = [[UIColor redColor] CGColor];
But do you guys now how I can replace the cu_email with the errorObject
?
Upvotes: 3
Views: 3149
Reputation: 107171
I think this will work for you:
You can access that textField property using KVC:
UITextField *theErrorField = (UITextField *)[self valueForKey:errorObject];
theErrorField.layer.borderColor = [[UIColor redColor] CGColor];
theErrorField.layer.borderWidth = 3.0;
Upvotes: 9