On OS X 10.10, is it possible to implement NSControl without NSCell?

I learn about NSControl . I know that NSCell began its path to obsolescence in OS X 10.10 Yosemite, so I would rather not use the API that goes away. In addition, the NSControl Class NSControl shows that all cell access devices are out of date.

I understand all this, but what is not so clear is what is recommended for people writing subclasses of NSControl in 10.10. All Apple manuals on this issue do not mention the obsolescence of NSCell . I believe that I could just do something the old way, but then I will need to change my code when Apple moves to the NSCell level to the next level.

Is it possible to implement a subclass of NSControl without using NSCell ?

Can someone give advice or link me to a resource on this? This is tricky for Google.

+6
source share
1 answer

I am also trying to do this. Unfortunately, I cannot answer all your questions, but here is what I have found so far.

The AppKit release notes for OS X v10.10 contain a brief explanation of what is happening, which I initially saw in the question How do I create a custom NSButton without subclassing NSButtonCell? .

NSCell gradual rejection

Mac OS X 10.10 takes another step towards the final cell. Direct access to the control's cell is discouraged and the methods that allow it will formally become obsolete in a future release. A variety of cell-level APIs were control subclasses to provide easy access to important functionality. NSLevelIndicator, NSTextField, NSSearchField, NSSlider, and NSPathControl have new properties for this purpose. Cellular NSTableViews are now deprecated, and view-based NSTableViews should be used instead. Matrix NSBrowsers are also deprecated in favor of an element-based interface.

There are many NSControl methods highlighted in red in the 10.10 documentation. (By the way, I'm not sure if this definitely means "deprecated.")

Documentation marking for continuous and enabled is misleading. I looked at the header file for NSControl in the ads that are crossed out in the documents, and it seems that several different events are happening:

  • This method has been 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 the 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 are completely removed:

     -userInterfaceLayoutDirection -setUserInterfaceLayoutDirection 
  • These declarations were previously methods, but were reorganized into properties. For more on what happened to the isEnabled / setEnabled methods, see this answer . Thus, these declarations are crossed out in the documents, but this is misleading:

     @property (getter=isContinuous) BOOL continuous; @property (getter=isEnabled) BOOL enabled; 

I did not find any good information on how to subclass NSControl without creating a subclass of NSCell , although apparently NSColorWell is without an NSControl cell.

My current crude conclusion is that NSControl quite strongly associated with NSCell , and it is not wise to use it without the other. Therefore, I am considering the possibility of subclassing NSView .

I would also like to get more information and tips here!

+3
source

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


All Articles