Skip to content

Instantly share code, notes, and snippets.

@roolo
Created January 12, 2012 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roolo/1599797 to your computer and use it in GitHub Desktop.
Save roolo/1599797 to your computer and use it in GitHub Desktop.
Your First Mac App -- updateUserInterface reference issue
#import <Cocoa/Cocoa.h>
@class Track;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *textField;
@property (weak) IBOutlet NSSlider *slider;
@property (strong) Track *track;
- (IBAction)takeFloatValueForVolumeFrom:(id)sender;
- (IBAction)mute:(id)sender;
- (void)updateUserInterface;
@end
#import "AppDelegate.h"
#import "Track.h"
@implementation AppDelegate
@synthesize track;
@synthesize window = _window;
@synthesize textField = _textField;
@synthesize slider = _slider;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
Track *aTrack = [[Track alloc] init];
[self setTrack:aTrack];
}
- (IBAction)takeFloatValueForVolumeFrom:(id)sender {
float newValue = [sender floatValue];
[self.track setVolume:newValue];
[self updateUserInteface];
}
- (IBAction)mute:(id)sender {
[self.track setVolume:0.0];
[self updateUserInterface];
}
- (void)updateUserInterface {
float volume = [self.track volume];
[self.textField setFloatValue:volume];
[self.slider setFloatValue:volume];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment