0

モデル

extension MyEntity {

    @nonobjc public class func fetchRequest() -> NSFetchRequest< MyEntity > {
        return NSFetchRequest< MyEntity >(entityName: "MyEntity")
    }

    @NSManaged public var customFields: NSDictionary?
}

customFields のキーと値は文字列です。

バインディング

ユーザーは列を追加/削除できるため、列はコードで作成されます。

column.bind(NSBindingName.value, to: treeController!, withKeyPath: "arrangedObjects.customFields.\(uniqueID))", options: [.createsSortDescriptor:false])
column.sortDescriptorPrototype = NSSortDescriptor(key: "customFields.\(uniqueID))", ascending: true, selector: #selector(NSString.compare(_:)))

問題

列ヘッダーをクリックすると、並べ替えが機能しません。値は単なる文字列ですが、そのようには見なされていないようです。問題がどこにあるのか、何か考えはありますか? ありがとう!

アップデート

  • NSTreeControllerエンティティ モードです
  • これはビューベースのアウトライン ビューです (セル ベースは現在も使用されていますか??)
  • 静的列 (IB で定義) の場合、並べ替えが機能します
  • 動的列を並べ替えても、何も起こりません (エラーなし)
  • ジェネリックを使用しないNSDictionaryなので、値は文字列とは見なされないと思います

更新 2

別のプロジェクトでは、成功しました。唯一の違いは、ディクショナリは ではなく、 whereMyObjectにはタイプのvalueプロパティがあることStringです。並べ替えは、次のコードを使用して有効にします。

/* Bind column for sorting */
column.bind(NSBindingName.value, to: resultsArrayController!, withKeyPath: "arrangedObjects.dictionary.\(String(describing: paramDef.objectID)).value", options: nil)

またはこれも同様に機能します:

column.sortDescriptorPrototype = NSSortDescriptor(key: "dictionary.\(String(describing: paramDef.objectID)).value", ascending: true, selector: #selector(NSString.compare(_:)))

上記ではなく、その場合に機能する理由がわかりません。

4

1 に答える 1