I am learning about NSControl
. I am aware that NSCell
has begun its road to deprecation in OS X 10.10 Yosemite, and so I'd rather not use an API that is going away. Also, the NSControl
Class Reference shows all cell accessors have been deprecated.
I understand all this, but what is not as clear is what the recommended course is for people writing NSControl
subclasses on 10.10. All of the Apple guides on the subject make no mention of the deprecation of NSCell
. I suppose I could just do things the old way, but then I'd need to change my code when Apple advances the deprecation of NSCell
to the next level.
Is it even possible to implement an NSControl
subclass without using NSCell
at all?
Can anyone provide advice or link me to a resource on this subject? This is proving difficult to google.
I'm trying to work this out as well. I can't unfortunately answer all your questions, but here's what I've found so far.
The AppKit Release Notes for OS X v10.10 have a brief explanation of what is happening, which I originally saw in the question How to create a custom themed NSButton without subclassing NSButtonCell?.
Gradual deprecation of NSCell
Mac OS X 10.10 takes another step towards the eventual deprecation of cells. Direct access to the cell of a control is discouraged, and methods which allow it will be formally deprecated in a subsequent release. A variety of cell-level APIs have been promoted to various Control subclasses in order to provide cell-free access to important functionality. NSLevelIndicator, NSTextField, NSSearchField, NSSlider, and NSPathControl all have new properties for this purpose. Cell-based NSTableViews are now deprecated, and view-based NSTableViews should be used instead. Matrix-based NSBrowsers are also deprecated in favor of the item-based interface.
The 10.10 documentation does have many NSControl methods crossed out in red. (By the way, I'm not sure if this unambiguously means "deprecated".)
The documentation markings for continuous
and enabled
are misleading, however. I've looked through the header file for NSControl
at the declarations that are crossed out in the docs and there seem to be a few different things going on:
This method is deprecated with
NS_DEPRECATED_MAC
:// Use formatters instead. See -[NSControl formatter] and -[NSControl setFormatter:]. - (void)setFloatingPointFormat:(BOOL)autoRange left:(NSUInteger)leftDigits right:(NSUInteger)rightDigits NS_DEPRECATED_MAC(10_0, 10_0);
These methods appear in an
NSDeprecated
category:@interface NSControl (NSDeprecated) // Use formatters instead. See -[NSControl formatter] and -[NSControl setFormatter:]. - (void)setFloatingPointFormat:(BOOL)autoRange left:(NSUInteger)leftDigits right:(NSUInteger)rightDigits NS_DEPRECATED_MAC(10_0, 10_0); + (void)setCellClass:(Class)factoryId; + (Class)cellClass; - (id)cell; - (void)setCell:(NSCell *)aCell; - (id)selectedCell; - (NSInteger)selectedTag; - (void)setNeedsDisplay; // Use setNeedsDisplay:YES instead. - (void)calcSize; - (void)updateCell:(NSCell *)aCell; - (void)updateCellInside:(NSCell *)aCell; - (void)drawCellInside:(NSCell *)aCell; - (void)drawCell:(NSCell *)aCell; - (void)selectCell:(NSCell *)aCell; @end
These methods appear in the documentation as "Available in OS X v10.8 through OS X v10.9", but not in the NSControl header file, so I assume they've been removed completely:
-userInterfaceLayoutDirection -setUserInterfaceLayoutDirection
These declarations were previously methods, but have been refactored into properties. See this answer for details about what happened to the isEnabled / setEnabled methods. So these declarations are crossed out in the docs, but this is misleading:
@property (getter=isContinuous) BOOL continuous; @property (getter=isEnabled) BOOL enabled;
I haven't found any good information about how to create an NSControl
subclass without also creating an NSCell
subclass, although apparently NSColorWell
is a cell-less NSControl
.
My current rough conclusion is that NSControl
is coupled fairly strongly to NSCell
, and it isn't sensible to use one without the other. So I'm considering writing an NSView
subclass instead.
I'd also appreciate more information and advice here!
来源:https://stackoverflow.com/questions/30746755/in-os-x-10-10-can-i-implement-an-nscontrol-without-an-nscell