目前,我正在与QDynamicDataSection of QuickDialog做斗争。我想填充一个动态部分。当我从演示中运行以下代码时,我得到一个动态部分,其中填充了模板的几个实例,即“这里有东西”。然而,我想得到“第一”和“第二”。这是如何达到的呢?
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]];用解决方案编辑:
爱德华多让我走上了正确的轨道(并获得了荣誉):
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 :我建议采用SampleDataBuilder.m的考试代码。
第二版与self的方法(见Eduardo的评论)也很有效。
发布于 2012-06-18 16:08:40
“迭代”键简单地遍历字典中的项,并根据每个元素的模板创建一个新元素。它还将新项绑定到数组中的对象。
但是,在您的示例中,模板没有定义任何绑定,因此创建的新项没有修改任何值。您必须添加类似“bind”、@"title:object“之类的内容。(对象返回正在绑定的实际对象,因此不对其属性绑定。
https://stackoverflow.com/questions/11086529
复制相似问题