2011-05-14 69 views
0

使用IB綁定對NSTableColumn中的綁定數據進行排序。如何使用InterfaceBuilder綁定對NSTableColumn中的綁定數據進行排序?

鍵:NSTableColumn,排序,NSArrayController的,內容集

甲contentSet供應像TableColumn中

這涉及用兩個單柱NSTableViews 一個SPLITVIEW一個數據源的TableViews的名稱是BookCategory和 書。 Books Table有一個帶有book_titles的單個列。 Class BookCategory對於Book有一對多關係 。

的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 

要重申的問題,與書名 負荷排序,則實現代碼如下。只有在用戶首先點擊 列標題後才能排序。

說有三個書類別藝術,歷史,體育。 當應用程序加載左表的SPLITVIEW進行排序, 那就是:

Art 
History 
Sports 

當用戶選擇任何類別,在類別中的所有書籍 標題出現在右邊的tableView但無序。 如果用戶單擊book_title TableColumn 的標題,則在列上完成初始排序。此後, 對任何書籍類別的選擇導致在右側tableView中book_titles的排序顯示 。也就是說,只有第一個 選擇的類別會導致未分類的書名稱列表。

非常感謝您的閱讀,馬克

回答

0

這是我終於爲之工作的綱要。

  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   
相關問題