3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NSOutlineView の使い方

Last updated at Posted at 2015-07-19

OSX の特殊なディレクトリであるパッケージの内容を表示するアプリの例。

x.tiff

プロジェクトの作成

Cocoa Application を Use Storyboards と Document Based にチェックして作成する。
Tragets - Info - Document Types で
 Extensions を指定する。(この例では xcodeproj)
 Document si distributed as a bundle をチェックする。

Documentクラスに書き加える内容

var	fileWrapper	= NSFileWrapper( directoryWithFileWrappers:[:] )
override func
readFromFileWrapper(
	fileWrapper		: NSFileWrapper
,	ofType typeName	: String
) throws {
	self.fileWrapper = fileWrapper
}

NSFileWrapper クラスの拡張

extension
NSFileWrapper {
	func
	children() -> [ NSFileWrapper ]? {
		if let wFWs = fileWrappers {
			var v = [ NSFileWrapper ]()
			for ( _, value ) in wFWs {
				v.append( value )
			}
			return v
		} else {
			return nil
		}
	}
	func
	isLeaf() -> Bool {
		return !directory
	}
}

Storyboard

NSTreeController と NSOutlineView を配置

  • NSTreeController の Key Paths

    • Children に chidren
    • Leaf に isLeaf
    • (Count は空白でいい)
  • NSOutlineView

    • cell based にする。
    • Columns を1に

バインディング

  • NSTreeController / Content Array

    • Bind to ViewController
    • Controller key / 空白
    • Model key Path / view.window.windowController.document.fileWrapper.children
  • NSOutlineView / TableColumns

    • Bind to Tree Controller
    • Controller Key / arrangedObject
    • Model Key Path / filename

ソース

GitHub https://github.com/Satachito/Samples 上に置いておきました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?