Currently, I struggle with the QDynamicDataSection of QuickDialog. I want to populate a dynamic section. When I run the following code, taken from the demo, I get a dynamic section populated with several instances of the template, i.e. "Something here". However, I want to get "first" and "second". How can this be reached?
QDynamicDataSection *section = [QDynamicDataSection new];
section.title = @"Normal: with elements";
section.bind = @"iterate:something";
section.elementTemplate = [NSDictionary dictionaryWithObjectsAndKeys:
@"QLabelElement", @"type",
@"Something here", @"title",
nil];
[root addSection: section];
[root bindToObject:[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:@"first", @"second", nil], @"something",
nil]];
EDIT with solution:
Eduardo set me on the right track (and gets the credit):
- The template has to provide a binding
- The array elements to iterate over have to be key compilant, e.g., dictionaries. (bind to
object
does not seem to work)
The following code works as intended:
QDynamicDataSection *section = [QDynamicDataSection new];
section.title = @"Normal: with elements";
section.bind = @"iterate:something";
section.elementTemplate = [NSDictionary dictionaryWithObjectsAndKeys:
@"QLabelElement", @"type",
@"title:name", @"bind",
nil];
[root addSection: section];
[root bindToObject:[NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObject: @"first" forKey: @"name"],
[NSDictionary dictionaryWithObject: @"second" forKey: @"name"],
nil], @"something",
nil]];
return root;
@Eduardo Scoz: I would suggest to adopt the exampe code in SampleDataBuilder.m
.
2nd Edit
The approach with self
(see comment by Eduardo) works, too.