Cocoa Bindings - NSTableView - 交换值 [英] Cocoa Bindings - NSTableView - Swapping Values

查看:175
本文介绍了Cocoa Bindings - NSTableView - 交换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSValueTransform子类是在显示以下内容的UI视图中显示Core Data属性的好选择:

Is an NSValueTransform subclass a good choice for displaying Core Data attributes into UI views displaying:


  1. ,2,3等)转换为诸如(Pending,Completed,Frozen,In progress等)之类的字符串

  2. 一个数字字符串(0,1) (red.png if 0,green.png if 1)



这里是Core Data显示的两个属性,计时器和状态:

Here's what Core Data displays for the two attributes, timer and status:

>

这里是我想要显示的,而不改变Core Data中的值:

Here is what I want to be displayed instead, without changing the values in Core Data:

如果不使用NSValueTransformer,其他方式是可能?

If not to use NSValueTransformer, in what other way is this possible?

我不想看到永久转换的数据,只是为了减少存储在Core Data中的数据和更好的UI视图项目。

I do not want to see the data permanently converted, only for the benefit of less data stored in Core Data and better UI view items.

我还试图修改托管对象类中的属性(没有KVO通知),没有运气。

I have also tried to modify the attributes in the managed object class (with out KVO notification) with no luck.

推荐答案

我最初使用的是什么,最初似乎是阻止显示不同的信息,在这些单元格,使用:

I ended up using what at first appeared to be blocking the display of different info in those cells, using:

#pragma mark - Table View Delegate

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    /*  tableColumn = (string) @"AutomaticTableColumnIdentifier.0"
                row = (int)    0          */
    NSString *identifier = [tableColumn identifier];
    NSTableCellView *cellView = [tableView makeViewWithIdentifier:identifier owner:self];

    NSManagedObject *item = [self.itemArrayController.arrangedObjects objectAtIndex:row];

    if ([identifier isEqualToString:@"AutomaticTableColumnIdentifier.0"]) {
        /*  subviews returns array with  0 = Image View &
                                         1 = Text Field      */
        /*  First, set the correct timer image  */
        ...  logic  ...
        NSImageView *theImage = (NSImageView *)[[cellView subviews] objectAtIndex:0];
        theImage.image = [NSImage imageNamed:@"green.gif"];

        /*  Second, display the desired status  */
        NSTextField *theTextField = (NSTextField *)[[result subviews] objectAtIndex:1];
        ...  logic  ...
        theTextField.stringValue = @"Pending";
    }

    return cellView;
}

Apple的文档声明(某处)与数组控制器的绑定可以组合与手动填充表视图单元格。看起来最好最简单的方法是从绑定开始,然后手动优化显示值。

Apple's documentation states (somewhere) that bindings with an Array Controller can work in combination with manually populating the table view cells. It seems best and easiest to start with bindings and then refine display values manually.

这篇关于Cocoa Bindings - NSTableView - 交换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆