Reputation: 11495
I got a very simple app. it gets slider value and display it on text box. The interface and implementation is as follow:
#import <Foundation/Foundation.h>
@interface HelloWorld : NSObject
@property (assign) IBOutlet NSTextField *Tf;
@property (assign) IBOutlet NSSliderCell *Sc;
@end
#import "HelloWorld.h"
@implementation HelloWorld
@synthesize Tf;
@synthesize Sc;
- (IBAction)Pressed:(id)sender {
[Tf setStringValue:@"Hey"];
}
- (IBAction)Scroll:(id)sender {
[Tf setStringValue: [Sc indexOfTickMarkAtPoint]];
}
@end
The UI:
Problem: The app crashes when I move the slider.
Upvotes: 0
Views: 1490
Reputation: 2277
Whats happening is its an NSInteger and not a pointer to an Object
[Tf setIntegerValue:[Sc indexOfTickMarkAtPoint]];
Upvotes: 1
Reputation: 31026
indexOfTickMarkAtPoint
returns NSInteger but setStringValue:
wants (somewhat obviously) a string. Look at the documentation for NSString method stringWithFormat:
for a description of how to do the conversion.
Something like:
[Tf setStringValue:[NSString stringWithFormat:@"%d", [Sc indexOfTickMarkAtPoint]]];
Upvotes: 1