In OS X 10.10, can I implement an NSControl without an NSCell?

社会主义新天地 提交于 2019-12-20 12:41:14

问题


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.


回答1:


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:

  1. 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);
    
  2. 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
    
  3. 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
    
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!