Now that we have NSTableView and NSOutlineView that can have regular NSView objects as their cells, what about NSBrowser? That is can we use regular NSView objects as cells in NSBrowser?
Short answer: No, not yet
NSOutlineView is a subclass of NSTableView so both of them got the upgrade to be able to use NSView objects as cells in Mac OS X 10.7. This is specifically called out at the beginning of the documentation for NSTableView:
Table views are displayed in scroll views. Beginning with OS X v 10.7 NSView instances (most commonly NSTableCellView instances or a subclass) are supported for rows and columns. Alternatively, NSCell subclass instances can be used for each row and column item.
On the other hand for NSBrowser it says specifically:
This class uses the NSBrowserCell class to implement its user interface.
Related
I want to detect when cells in NSTableView become invisible when the user scrolls. In iOS, the UITableView has a delegate method with signature tableView:didEndDisplayingCell:forRowAtIndexPath, but I could not find anything simular in the delegate methods of NSTableView.
I'm trying to find UITableView analog for OS X, but have no success. Maybe there is an external library? All I need is a ScrollView with cells that are customizable (NSView subclasses will be the best option).
Use NSTableView. From Apple's documentation:
An NSTableView object displays data for a set of related records, with rows representing individual records and columns representing the attributes of those records.
It has all of the features that you are looking for and is included in the core Cocoa library. It's very easy to use and nowadays table views are view-based by default when created with Interface Builder.
I have an NSView subclass that I'd like to use in an NSTableView. Normally of course I'd use a NSTableCellView subclass but this view will be used elsewhere.
Possible?
There's no requirement that the cell view used for a view-based table view be an NSTableCellView or subclass. It's perfectly OK to use an instance of some other view object. For example, an NSTextField works out of the box.
Your table view delegate's -tableView:viewForTableColumn:row: method can configure the view as appropriate for the row. Or, your view can implement an objectValue property (with -setObjectValue: setter). In this case, the table view will forward whatever object value your data source returns from its -tableView:objectValueForTableColumn:row: method to your view's objectValue property.
Also, if your view class has textField or imageView properties (like NSTableCellView does), then those will be treated specially in certain cases. For example, the text field will be the accessibility string for the cell.
Basically, all of the behaviors of NSTableCellView are generalizable. It's not that the class is treated particularly specially by the framework. It's that it provides the appropriate properties and methods and any view with those same properties and methods could replicate its behavior.
Change your NSView subclass to inherit from NSTableCellView instead of NSView, since NSTableCellView also inherits from NSView too.
I am wondering how to draw a NSTextFieldCell like the one in NetNewsWire.
I have already subclassed a NSTextFieldCell for the group cell and specified it in my PXSourceList's dataCellForItem.
The source list is cell based.
I just don't know how to draw the cells.
Check out the Apple sample "SourceView", that contains a subclass of NSTextFieldCell called ImageAndTextCell that does what you want.
https://developer.apple.com/library/mac/#samplecode/SourceView/Introduction/Intro.html
Though if it were me, I'd change to using a view based OutlineView and use the built in NSTableCellView which already supports an imageView.
Is it possible to bind a NSArraycontroller with NSTableView whose cells are not text cells but nstablecellview? I'm new to cocoa programming, tried searching on this but no proper explanation on this.
Yes, it's possible. You can set the NSTableView to View based.
Instead of binding to the column, bind the cell UI element (e.g. NSTextField) to the "Table Cell View" using objectValue.propertyName
Ref:
http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
http://www.raywenderlich.com/21752/how-to-use-cocoa-bindings-and-core-data-in-a-mac-app