Question

I´m working on a CustomSlider Class. In my project I have three sliders which all have the class CustomSlider. I want these three sliders to have different knobs. See Picture.

Since the sliders already have tags I decided to use them for this purpose. Unfortunately I don´t see how to get tag value of the NSSliderCell.

I tried this:

int myTag = [self tag];

and this:

NSButton *button = [super self];
int myTag = [button tag];

Both without success, any idea? Is there another way to let the class know which object is sending the message?

Greetings, Ronald

enter image description here

Était-ce utile?

La solution

The tag is a long. NSSliderCells inherit their tag from NSActionCell, so have a tag separate from the NSSlider which uses the NSSliderCell, which inherits its tag from NSControl. In a custom NSSliderCell class, [self tag] does return the tag set for the sliderCell in the XIB.

Here is the header for a custom slider cell class:

#import <AppKit/AppKit.h>
@interface EWSliderCell : NSSliderCell
@end

and here is the whole of the class itself:

#import "EWSliderCell.h"
@implementation EWSliderCell
-(NSRect)rectOfTickMarkAtIndex:(NSInteger)index {
    static BOOL reportedTag;
    if (!reportedTag) {
        long myTag = [self tag];
        NSLog(@"myTag=%ld", myTag);
        reportedTag = TRUE;
    }
    return CGRectMake(0.0, 0.0, 0.0, 0.0); // remove the tick marks from the slider
}
@end

and this does execute and report the correct tag.

I'm not able to replicate the error message you report. However, if I (erroneously) write myTag = [EWSliderCell tag]; then I see the message "No known class method for selector 'tag'. tag is not a class method, it's an instance method. (Is that the right word?) Can you post the code which produced the error message?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top