【问题标题】:How do you Sort Bound Data in NSTableColumn using InterfaceBuilder binding?如何使用 InterfaceBuilder 绑定对 NSTableColumn 中的绑定数据进行排序?
【发布时间】:2013-10-21 22:45:56
【问题描述】:

使用 IB 绑定对 NSTableColumn 中的绑定数据进行排序。

键:NSTableColumn、排序、NSArrayController、内容集

contentSet 就像 TableColumn 的数据源

这处理带有两个单列 NSTableViews 的 SplitView 表视图的名称是 BookCategory 和 图书。 Books 表有一个带有 book_titles 的列。 Class BookCategory 具有一对多的关系 预订。

BookCategory 表在加载时使用:

@implementation MyBookCategoryController

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
       NSSortDescriptor *descript = 
       [NSSortDescriptor sortDescriptorWithKey:@"name"
                    ascending:YES selector:@selector(caseInsensitiveCompare:)];

       [self setSortDescriptors:[[NSArray arrayWithObject:descript] autorelease] ];

    }
    return self;
}

This same approach fails to sort the BookTitle table at load.  !!

The BookTitle table/column loads unsorted.

For the TableColumn the Attributes Inspector has  
 Sort Key:title
 Selector: caseInsensitiveCompare:
 Order: Ascending

这似乎是在单击时启用排序 在列标题上。

I want the data sorted when the view loads. 

The binding inspector for this book_title column has:
 Value : BookCategoryArrayController.arrangedObjects.name

The BookTitleArrayController in binding inspector shows 
 Content Set: Book Category ArrayController.selection.books

为了重申问题,带有书名的表格视图 加载未排序。只有在用户第一次点击 列标题。

假设有艺术、历史、体育三类书籍。 当app在splitview中加载左表时进行排序, 那就是:

Art
History
Sports

当用户选择任何类别时,所有书籍的标题 在类别中出现在右侧的 tableView 但未排序。 如果用户点击 book_title TableColumn 的 Header 初始排序是在列上完成的。此后 选择任何书籍类别都会导致排序显示 右侧 tableView 中的 book_titles。也就是说,只有第一个 选择一个类别会产生一个未排序的书名列表。

非常感谢您的阅读,马克

【问题讨论】:

    标签: sorting set nsarraycontroller nstablecolumn


    【解决方案1】:

    这是最终对我有用的大纲。

                Sorting with CategoryArrayController (NSArrayController)
    
          Bindings Inspector
             Content Set  Bind to: CategoryArrayController.selection.books
    
             SortDescriptors Bind to: ShareUserDefaultsController
              Controller Key: values
              sortDescriptors  (note:  exclamation point)
              NSUnarchiveFromData
    
        Shared User Defaults Controller 
            Referencing Outlets
              userDefaultsController -- AppController (C:AppController)
            Referencing Bindings
                values.sortDescriptors -- Sort Descriptors Rx Array Controller (C:NSArrayController)
                                       -- Sort Descriptors Category Array Controller (C:NSArrayController)  
    
          Clicking on Category Header does no sort. Selects all in Cats, and empties Recipe Table
          Comments on the above welcome.
    
        TableViewCat (NSTableController)
            Attributes Inspector
              TableView
                Selection 
                    Empty,Column,Type Select
              Control
                 State.Enabled
            Connections Inspec
                None
            Bindings Inspec
                None
    
          TableColumn -Category (NSTableColumn)
            Attributes Inspec
                Sort Key : None
            Bindings Inspec
                Value -- Category Array Controller.arrangedObjects.name
    
    
        Sorting with RxArrayController (C:NSArrayController)
          Attributes Inspec
             Array Controller: 1-5 of 6
             Object Controller
               EntityName: Recipe
                 Prepares Content
                 Editable
          Connections Inspector
            Referencing Bindings
              arrangedObjects.name -- Value - Table Column Recipe
              selectedObjects      -- Double Click Argument - Table View Book
          Bindings Inspector
           Controller Content
             Content Set
               Category Array Controller.selection.books
           Controller Content Parameters    
             Sort Descriptors Bind to: ShareUserDefaultsController
              Controller Key: values
              sortDescriptors  (note:  exclamation point)
              NSUnarchiveFromData
            Parameters  
              Managed Object Context(App Delegate.manangedObjectContext
    
        TableView Book (NSTableView)
            Attributes Inspector
              TableView
                Selection Empty,Column,Type Select
              Control
                State.Enabled
            Connections Inspec
                Bindings
                    DoubleClick Argument -- Book Array Controller.selectedObjects
                    Double Click Target  -- App Delegate.self
            Bindings Inspec
                Double Click Argument (Book Array Controller.selectedObjects)
                Double Click Target (App Delegate.self)
                    Bind To: App Delegate
                        Model Key Path: self  (Repeats ?)
                        Selector Name: newBookAction: 
                          Conditionally Sets Enabled
    
          TableColumn - Book (NSTableColumn)
            Attributes Inspec
                Sort Key : None
            Connections Inspec
                Bindings
                    Value -- Book Array Controller.arrangedObjects.name
            Bindings Inspec
                Value -- Book Array Controller.arrangedObjects.name         
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 2023-03-22
      • 2018-02-17
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多