【问题标题】:Obtaining attribute data from an array controller从数组控制器获取属性数据
【发布时间】:2012-04-24 15:51:55
【问题描述】:

在 Apple Core Data 上的 guide 之后,我将我的应用程序部署到了两个表视图。第一个创建假期组,第二个包括先前创建的组的所有庆祝活动。该技术是绑定之一。表格视图连接到两个阵列控制器。第一个数组控制器管理节日组的实体,第二个管理个别节日的实体,并具有两个属性:名称和日期。现在我需要获取 Array 中包含的日期以在应用程序中使用。最简单的方法是什么?

【问题讨论】:

    标签: objective-c xcode core-data nsarraycontroller


    【解决方案1】:

    如果我自己不遵循教程,我实际上无法评论您的实现,但我可以发表一般评论。

    也许您想遍历 selectedObjects?

        // When bound to a row, 1 object = 1 row
        for (Entity *entity in arrayController_.selectedObjects) {
            // Use your entity here ie:
            NSLog(@"The entity's date is %@", entity.date);
        }
    

    您也可以将值绑定到 TableCellView 的 objectValue

    1. Select the TableCellView
    2. Add a label
    3. Bind the value of the new label to the TableCellView
    4. Set the Model Key Path to 'objectValue.date' 
    

    希望对你有帮助

    【讨论】:

    • 感谢您的回复。我尝试添加您的代码,但出现编译错误,我确定我错了。我的实体称为“FesteGruppo”,属性称为“日期”。如何调整您的代码?
    • 您是否在目标文件中包含实体标头,即:在您的.m 文件顶部您应该有#import "FesteGruppo.h"? for 循环应该类似于 for (FesteGruppo *festeGruppoEntity in ...)
    • 你好,我按照你说的做了,情况有所改善,但是还是出现编译错误:Use of undeclared identifier "arrayController_" 你的意思是“NSArrayController”吗?我该如何解决这个问题?
    • 当您在 Interface Builder 中创建对象时,该对象仅存在于 XIB 文件的范围内。要访问它,您需要创建一个 IBOutlet 并连接它。在您的 .h 文件中,按照以下行创建一个 ivar:IBOutlet NSArrayController *arrayController_;,在 Interface Builder 中按住 CTRL 键将阵列控制器拖动到 Files Owner,选择此插座。也结帐Youtube
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多