Welcome, Guest
Username Password: Remember me

Can it get easier? (Multiple custom cells in grouped table section)
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Can it get easier? (Multiple custom cells in grouped table section)

Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #1

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
Attachments:
  • RalfR
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0
--
twitter: twitter.com/24z
about: about.me/24z

Re: Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #2

I noticed, that my question comes down to this:

Is there an easy way to pass data to a SCControlCell without using an intermediate value object?
  • RalfR
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0
--
twitter: twitter.com/24z
about: about.me/24z

Re: Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #3

Hey Ralf,

One of the main advantages of STV's key-binding method is that it allows you to quickly read/write values into cells without having any bound objects. In your case, the code should look something like this:

 
...
[tableModel.modelKeyValues setValue:@"Phone Number" forKey:@"PhoneTitleText"];
[tableModel.modelKeyValues setValue:@"+49-111-222-333" forKey:@"PhoneNoText"];
 
NSDictionary *cellContent = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"PhoneTitleText", @"PhoneNoText", nil] forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
SCControlCell *dentistEmailCell = [SCControlCell cellWithText:nil withKeyBindings:cellContent withNibName:@"CustomCell"];
...
 


Also, if PhoneTitleText was a static label that will not change, then you should probably set it in Interface Builder. Please tell me if this makes your life easier
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Last Edit: 1 year, 1 month ago by tarekskr. Reason: Glitch in code

Re: Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #4

PERFECT!

Just added a custom SCControlCell into a grouped UITableView which contains a MKMapView with rounded corners. All works perfectly fine with STV. Amazing. Stunning. Breathtaking.

I'm kind of doing a version 2.0 of an app that I submitted to the App Store in the very beginning. Honestly, STV saved me, without exaggeration, 7-10 days. I know this, because I did all of this stuff manually for version 1.0.

It's great. We just need to work on the documentation (videos, tutorials, wiki).
  • RalfR
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0
--
twitter: twitter.com/24z
about: about.me/24z

Re: Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #5

Ups... that success response was a bit to early. I did the following

 
NSDictionary *dentistContactBindings = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"label", @"value", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
// Telefon
[tableViewModel.modelKeyValues setValue:@"Telefon" forKey:@"label"];
[tableViewModel.modelKeyValues setValue:theDentist.telefon forKey:@"value"];
 
SCControlCell *dentistTelefonCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistContactBindings
withNibName:@"DentistContactCell"];
[contactSection addCell:dentistTelefonCell];
 
 
// E-Mail
[tableViewModel.modelKeyValues setValue:@"E-Mail" forKey:@"label"];
[tableViewModel.modelKeyValues setValue:theDentist.email forKey:@"value"];
 
SCControlCell *dentistEmailCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistContactBindings
withNibName:@"DentistContactCell"];
[contactSection addCell:dentistEmailCell];
 
 
// Internet
[tableViewModel.modelKeyValues setValue:@"Internet" forKey:@"label"];
[tableViewModel.modelKeyValues setValue:theDentist.web forKey:@"value"];
 
SCControlCell *dentistInternetCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistContactBindings
withNibName:@"DentistContactCell"];
 
[contactSection addCell:dentistInternetCell];
 


The result is attached. Any idea?
Attachments:
  • RalfR
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0
--
twitter: twitter.com/24z
about: about.me/24z

Re: Can it get easier? (Multiple custom cells in grouped table section) 1 year, 1 month ago #6

Ended up using the following, which works. So, I still think if you would add an additional initializer to SCControlCell that would just let us pass in n values for n tags, that would dramatically simplify this kind of setup!

I'd love to bind the control with tag 1 to "Telefon" and the control with tag 2 to "+49-111-222" with just one single line a la:

 
SCControlCell *myCell = [SCControlCell cellWithValuesForTags:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Telefon", @"+49-111-222", nil] forKeys:[NSArray arrayWithObjects:@"1", @"2"]];
 


Currently, I have to do it like this:

 
NSDictionary *dentistTelefonBindings = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"labelTelefon", @"valueTelefon", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
// Telefon
[tableViewModel.modelKeyValues setValue:@"Telefon" forKey:@"labelTelefon"];
[tableViewModel.modelKeyValues setValue:theDentist.telefon forKey:@"valueTelefon"];
 
SCControlCell *dentistTelefonCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistTelefonBindings
withNibName:@"DentistContactCell"];
[contactSection addCell:dentistTelefonCell];
 
 
// E-Mail
NSDictionary *dentistEmailBindings = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"labelEmail", @"valueEmail", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
 
[tableViewModel.modelKeyValues setValue:@"E-Mail" forKey:@"labelEmail"];
[tableViewModel.modelKeyValues setValue:theDentist.email forKey:@"valueEmail"];
 
SCControlCell *dentistEmailCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistEmailBindings
withNibName:@"DentistContactCell"];
[contactSection addCell:dentistEmailCell];
 
 
// Internet
NSDictionary *dentistInternetBindings = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"labelInternet", @"valueInternet", nil]
forKeys:[NSArray arrayWithObjects:@"1", @"2", nil]];
 
[tableViewModel.modelKeyValues setValue:@"Internet" forKey:@"labelInternet"];
[tableViewModel.modelKeyValues setValue:theDentist.web forKey:@"valueInternet"];
 
SCControlCell *dentistInternetCell = [SCControlCell cellWithText:nil
withKeyBindings:dentistInternetBindings
withNibName:@"DentistContactCell"];
 
  • RalfR
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Karma: 0
--
twitter: twitter.com/24z
about: about.me/24z
  • Page:
  • 1
  • 2
Time to create page: 2.87 seconds