如何使用 InterfaceBuilder 绑定对 NSTableColumn 中的绑定数据进行排序?

发布于 2024-11-06 22:21:54 字数 1694 浏览 7 评论 0原文

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

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

contentSet 充当 TableColumn 的数据源,

它处理具有两个单列 NSTableView 的 SplitView TableViews 的名称是 BookCategory 和 图书。 书籍表有一个包含 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

为了重述问题,带有书名的表格视图 加载未排序。仅在用户第一次单击后才排序 列标题。

假设有三个书籍类别:艺术、历史、体育。 当应用程序加载拆分视图中的左表时,它已排序, 即:

Art
History
Sports

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

非常感谢您的阅读,马克

Sorting Bound Data in NSTableColumn using IB binding.

Keys: NSTableColumn , sorting, NSArrayController, Content Set

A contentSet serves like a data source for a TableColumn

This deals with a SplitView with two single column NSTableViews
The names of the TableViews are BookCategory and
Books.
The Books Table has a single column with book_titles.
The Class BookCategory has a one to many relationship
to Book.

The BookCategory Table is sorted at load using:

@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

This appears to enable the sorting when one clicks
on the column header.

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

To restate the problem, the tableview with the book titles
load unsorted. It sorts only after the user's FIRST click on the
column header.

Say there are three book categories Art, History, Sports.
When the app loads the left table in the splitview is sorted,
that is :

Art
History
Sports

When the user selects ANY category, titles for all books
in the category appear in the right tableView but unsorted.
If the user clicks on the Header of the book_title TableColumn
the initial sorting is done on the column. Thereafter
the selection of ANY book category causes a sorted display
of book_titles in the right tableView. That is, ONLY the first
selection of a category results in an Unsorted book title list.

Thanks a lot for reading, Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下客 2024-11-13 22:21:54

这是最终对我有用的概述。

            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         

This is an outline of what finally worked for me.

            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         
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文