NSArrayController / NSTreeController and Cocoa Views

I have been reading Objective-C and Cocoa for some time, and I have to say that although I am delighted with the overall simplicity of Objective-C, I feel completely lost in relation to Cocoa and especially the MVC design pattern. In the Cocoa books that I read, ask the reader to simply follow the set of steps for the program to work, without going into details about the API mechanisms. I am trying to understand the general meaning of NSTableView, NSOutlineView, their data sources, their delegates and everything that they have to do with various controller classes such as NSArrayController and NSTreeController. Therefore, I have a couple of questions:

  • How do these classes really interact?
  • Is the NSTableView data source an instance of NSArrayController?
  • Should the delegate and data source be the same class in NSTableView or NSOutlineView?
  • Leaving the binding aside, do NSArrayController and NSTreeController have other important benefits?

Suppose there is a container (in C) with some data (C struct). We want to show this data in an NSTableView (or NSOutlineView) and exchange views at runtime if the data structure is hierarchical. Should I create a class with NSArrayController (or NSTreeController) as an instance and wrap the functionality of the C container?

Thank you and forgive me for my stupid questions.

+3
source share
3 answers

. Cocoa. MVC Cocoa , .

, Cocoa, Cocoa Mac OS X Aaron Hillegass. , . ( iPhone) .

, C-, Objective-C ( , "M" MVC).

Controller NSOutlineView ( ). Cocoa, "". ( ). , , ( Cocoa, , , ). NSObject. NSOutlineViewDataSource. , , .

+3

?

TableView OutlineView ( ). , . "", ; , , , , ..

, , . , ; , , , , .. .

, NSArrayController: TableView/ . , , , , .., .

NSTableView NSArrayController?

, ; NSTableView .

, :

myArrayController.arrangedObjects.firstName 

arrangedObjects NSArrayController, firstName .

NSTableView NSOutlineView?

NSTableView. NSTableView, . NSArrayController NSTableView.

, . - .

+1

- , , - .

Datasource - , , .

( /, ), , .

NSArrayController , . ( , - - ), .

0
source

Source: https://habr.com/ru/post/1715996/


All Articles