Skip to content

Commit 7a7fea3

Browse files
add a view controller to encapsulate all of our slider stuff
1 parent 0c241ce commit 7a7fea3

7 files changed

+632
-468
lines changed

Classes/SliderViewController.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// SliderViewController.h
3+
// snappyslider
4+
//
5+
// Created by Aaron Brethorst on 12/15/12.
6+
//
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class SnappySlider;
12+
13+
@interface SliderViewController : UIViewController
14+
@property(nonatomic,strong) SnappySlider *codeSlider;
15+
@property(nonatomic,strong) IBOutlet SnappySlider *xibSlider;
16+
@property(nonatomic,strong) IBOutlet UILabel *codeLabel;
17+
@property(nonatomic,strong) IBOutlet UILabel *xibLabel;
18+
19+
- (IBAction)xibValueChanged:(id)sender;
20+
@end

Classes/SliderViewController.m

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// SliderViewController.m
3+
// snappyslider
4+
//
5+
// Created by Aaron Brethorst on 12/15/12.
6+
//
7+
//
8+
9+
#import "SliderViewController.h"
10+
#import "SnappySlider.h"
11+
12+
@implementation SliderViewController
13+
14+
- (void)viewDidLoad
15+
{
16+
[super viewDidLoad];
17+
18+
self.codeSlider = [[SnappySlider alloc] initWithFrame:CGRectMake(20, 61, 280, 23)];
19+
20+
NSArray *detents = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:20],
21+
[NSNumber numberWithInt:40], [NSNumber numberWithInt:60],
22+
[NSNumber numberWithInt:80], [NSNumber numberWithInt:100], nil];
23+
24+
self.codeSlider.detents = detents;
25+
self.xibSlider.detents = detents;
26+
27+
[self.codeSlider addTarget:self action:@selector(val:) forControlEvents:UIControlEventValueChanged];
28+
29+
[self.view addSubview:self.codeSlider];
30+
}
31+
32+
33+
- (void)val:(id)sender
34+
{
35+
self.codeLabel.text = [NSString stringWithFormat:@"Created in code: %.0f", self.codeSlider.value];
36+
}
37+
38+
- (IBAction)xibValueChanged:(id)sender
39+
{
40+
self.xibLabel.text = [NSString stringWithFormat:@"Created in XIB: %.0f", self.xibSlider.value];
41+
}
42+
43+
@end

Classes/snappysliderAppDelegate.h

+3-14
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,10 @@
2424
// THE SOFTWARE.
2525

2626
#import <UIKit/UIKit.h>
27-
#import "SnappySlider.h"
27+
#import "SliderViewController.h"
2828

29-
@interface snappysliderAppDelegate : NSObject <UIApplicationDelegate>
30-
{
31-
UIWindow *window;
32-
SnappySlider *slider;
33-
SnappySlider *xibSlider;
34-
35-
UILabel *codeLabel;
36-
UILabel *xibLabel;
37-
}
38-
@property(nonatomic,retain) IBOutlet SnappySlider *xibSlider;
39-
@property(nonatomic,retain) IBOutlet UILabel *codeLabel;
40-
@property(nonatomic,retain) IBOutlet UILabel *xibLabel;
29+
@interface snappysliderAppDelegate : UIResponder <UIApplicationDelegate>
30+
@property(nonatomic,retain) SliderViewController *viewController;
4131
@property (nonatomic, retain) IBOutlet UIWindow *window;
42-
- (IBAction)xibValueChanged:(id)sender;
4332
@end
4433

Classes/snappysliderAppDelegate.m

+2-83
Original file line numberDiff line numberDiff line change
@@ -24,98 +24,17 @@
2424
// THE SOFTWARE.
2525

2626
#import "snappysliderAppDelegate.h"
27-
#import "SnappySlider.h"
2827

2928
@implementation snappysliderAppDelegate
3029

31-
@synthesize window, xibLabel, codeLabel, xibSlider;
32-
33-
#pragma mark -
34-
#pragma mark Application lifecycle
35-
3630
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3731

38-
slider = [[SnappySlider alloc] initWithFrame:CGRectMake(20, 61, 280, 23)];
39-
40-
NSArray *detents = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:20],
41-
[NSNumber numberWithInt:40], [NSNumber numberWithInt:60],
42-
[NSNumber numberWithInt:80], [NSNumber numberWithInt:100], nil];
43-
44-
slider.detents = detents;
45-
xibSlider.detents = detents;
46-
47-
[slider addTarget:self action:@selector(val:) forControlEvents:UIControlEventValueChanged];
48-
49-
[self.window addSubview:slider];
50-
[slider release];
32+
self.viewController = [[SliderViewController alloc] initWithNibName:@"Slider" bundle:nil];
33+
self.window.rootViewController = self.viewController;
5134

5235
[self.window makeKeyAndVisible];
5336

5437
return YES;
5538
}
5639

57-
- (void)val:(id)sender
58-
{
59-
codeLabel.text = [NSString stringWithFormat:@"Created in code: %.0f", slider.value];
60-
}
61-
62-
- (IBAction)xibValueChanged:(id)sender
63-
{
64-
xibLabel.text = [NSString stringWithFormat:@"Created in XIB: %.0f", xibSlider.value];
65-
}
66-
67-
- (void)applicationWillResignActive:(UIApplication *)application {
68-
/*
69-
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
70-
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
71-
*/
72-
}
73-
74-
75-
- (void)applicationDidEnterBackground:(UIApplication *)application {
76-
/*
77-
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
78-
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
79-
*/
80-
}
81-
82-
83-
- (void)applicationWillEnterForeground:(UIApplication *)application {
84-
/*
85-
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
86-
*/
87-
}
88-
89-
90-
- (void)applicationDidBecomeActive:(UIApplication *)application {
91-
/*
92-
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
93-
*/
94-
}
95-
96-
97-
- (void)applicationWillTerminate:(UIApplication *)application {
98-
/*
99-
Called when the application is about to terminate.
100-
See also applicationDidEnterBackground:.
101-
*/
102-
}
103-
104-
105-
#pragma mark -
106-
#pragma mark Memory management
107-
108-
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
109-
/*
110-
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
111-
*/
112-
}
113-
114-
115-
- (void)dealloc {
116-
[window release];
117-
[super dealloc];
118-
}
119-
120-
12140
@end

0 commit comments

Comments
 (0)