2011-04-27 2 views

답변

12

빠르게 기입 예 :

SampleAppDelegate.h

#import <Cocoa/Cocoa.h> 

@interface SampleAppDelegate : NSObject <NSApplicationDelegate> { 

    NSWindow * window; 
    NSArray * values; 

    IBOutlet NSSlider * theSlider; 
    IBOutlet NSTextField * theLabel; 

} 

- (IBAction)sliderChanged:(id)sender; 

@property (assign) IBOutlet NSWindow *window; 

@end 

SampleAppDelegate.h

#import "SampleAppDelegate.h" 

@implementation SampleAppDelegate 

@synthesize window; 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

    values = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"10",@"50",nil]; 

    [theSlider setNumberOfTickMarks:[values count]]; 
    [theSlider setMinValue:0]; 
    [theSlider setMaxValue:[values count]-1]; 
    [theSlider setAllowsTickMarkValuesOnly:YES]; 

    [theLabel setStringValue:[values objectAtIndex:0]]; 
    [theSlider setIntValue:0]; 


} 

- (IBAction)sliderChanged:(id)sender { 

    int current = lroundf([theSlider floatValue]); 
    [theLabel setStringValue:[values objectAtIndex:current]]; 

} 

@end 

인터페이스 빌더 :
- NSSlider 추가 (IBOutlet/conn 연결 요법 IBAction를 활성화/통주 업데이트는)
- NSTextField있는()가

결과를 함께 IBOutlet 연결 추가

enter image description here

+0

일이 그 일의 권장되는 방법입니다. –

+0

대단히 감사합니다. 그 접근 방식은 훌륭하게 작동했습니다. –

+0

앤이 다시 공격합니다. 좋은 코드. :) –