How would I get the total number of rows in an NSOutlineView?
there is a method called numberOfRows, which returns a NSInteger. e.g. your NSOutlineView is called outlineView:
NSInteger *rows = [outlineView numberOfRows];
Documentation here:
"Typically you should not ask the table view how many rows it has; instead you should interrogate the table view's data source."
There is an informal protocol, if you are really insistent on using the tableView, which is:
– numberOfRowsInTableView: (NSTableDataSource informal protocol)
Does this include any subordinate rows in expanded rows? For example, if foo contains bar, baz, and qux, and is expanded, then bar, baz, and qux are visible rows as well. Conversely, if foo is not expanded, then bar, baz, and qux are not “rows in [the] NSOutlineView”—they exist only in your model.
Forget the outline view. It is irrelevant and confuses your question. You want to know how many of your model objects you have, so ask the controller that owns them.
People are saying “ask the data source” because that controller is the object that should be your view's data source. But forget the outline view, and forget its data source property. Talk to the controller directly. Ask it how many whatever-model-objects it has. If you want to know the deep version of the answer (how many things you have, including things in other things), ask it that. Either way, also implement a method in that controller to provide the answer.
Addendum: Remember the separation of powers in Cocoa. You have a model, which is the user's data in object form; views, which display the model to the user; and controllers, which own the model and the views. You say this isn't a drawing-related question; that makes it a question not for a view (“how many rows will you draw”), but a question for a controller (“how many <some-kind-of-thing>s do you own”). Therefore, you need to ask it of a controller.