目前,我在QuickDialog的 QDynamicDataSection 中挣扎。我想填充一个动态部分。当我运行以下从演示中获取的代码时,我得到一个动态部分,其中填充了模板的几个实例,即“这里的东西”。但是,我想获得“第一”和“第二”。这怎么能达到?
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]];
编辑解决方案:
Eduardo 让我走上了正确的道路(并获得了荣誉):
- 模板必须提供绑定
- 要迭代的数组元素必须是关键编译器,例如字典。(绑定
object
似乎不起作用)
以下代码按预期工作:
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:我建议采用SampleDataBuilder.m
.
第二次编辑self
(见 Eduardo 的评论)
的方法也有效。