首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QDynamicDataSection in QuickDialog

QDynamicDataSection in QuickDialog
EN

Stack Overflow用户
提问于 2012-06-18 15:55:27
回答 1查看 925关注 0票数 1

目前,我正在与QDynamicDataSection of QuickDialog做斗争。我想填充一个动态部分。当我从演示中运行以下代码时,我得到一个动态部分,其中填充了模板的几个实例,即“这里有东西”。然而,我想得到“第一”和“第二”。这是如何达到的呢?

代码语言:javascript
复制
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]];

用解决方案编辑

爱德华多让我走上了正确的轨道(并获得了荣誉):

  1. 模板必须提供绑定。
  2. 要迭代的数组元素必须是关键编译器,例如字典。(绑定到object似乎行不通)

下列代码按预期工作:

代码语言:javascript
复制
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的评论)也很有效。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-18 16:08:40

“迭代”键简单地遍历字典中的项,并根据每个元素的模板创建一个新元素。它还将新项绑定到数组中的对象。

但是,在您的示例中,模板没有定义任何绑定,因此创建的新项没有修改任何值。您必须添加类似“bind”、@"title:object“之类的内容。(对象返回正在绑定的实际对象,因此不对其属性绑定。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11086529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档