This might be a feature request, or I might miss something (pretty new to STV). Generally, I'd love to have an additional initializer for SCControlCell that would allow me to straightly pass in values for controls (tags). Anything along the lines of:
NSDictionary *cellContent = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Phone Number", @"+49-111-222-333", nil] forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
SCControlCell *dentistEmailCell = [SCControlCell cellWithText:nil withValueBindings:cellContent withNibName:@"CustomCell"];
The idea behind this is, that I frequently run into situations, where I don't want to bind a custom cell's content to an existing object or the TableViewModel's key/value dictionary.
Attached you find an example, where I want to use a single custom cell crafted with IB multiple times in a grouped section of a table. Basically, the custom cell holds just two styled labels. I want to pass in a value for the label (think "phone", "email", "skype", ...) and the corresponding value. So in this example, I want to add three custom cells, one for "phone", one for "email" and one for "skype". Obviously, my data model does not have properties for the text of the label.
As I couldn't find an easier way, I've created a helper model object, that holds a label and a value and pass that in using the standard object binding. However, I think it's a bit much code for something that simple.
Here is the code I'm currently using.
// E-Mail (This is a temporary value object, because SCControlCell does not seem to allow to pass in values for bound controls directly. So we need this as the data transfer object. (?)
DentistContactCellLabelValue *emailObject = [[DentistContactCellLabelValue alloc] init];
emailObject.label = @"E-Mail";
emailObject.value = theDentist.email; // <- theDentist is the "real" object
// No we bind the properties of the temporary value object
NSDictionary *dentistEmailBindings = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"label", @"value", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
SCControlCell *dentistEmailCell = [SCControlCell cellWithText:nil
withBoundObject:emailObject
withObjectBindings:dentistEmailBindings
withNibName:@"DentistContactCell"];
[contactSection addCell:dentistEmailCell];
I've attached screenshots of the end result and the custom cell as designed in IB.
Questions:
1.) Is there a more straight forward way to use custom cells where one or more controls need to be bound to values that do not exist in the model?
2.) Is there a completely different (better) way of achieving what I want to achieve?
3.) If the answer to 1 or 2 is "no", can you consider this as a feature request for an additional "withValueBindings:" initializer for SCControlCell?
Cheers,
Ralf