Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2010, 04:35 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Bangkok / Koh Samui Thailand
Posts: 25
maddams is on a distinguished road
Question Reload slider positions

I can reload slider values but not their previous positions. Positions resets to zero. Tried lots of experiments, checked Documentation, RTFM just not the right pages

.h file
#import <UIKit/UIKit.h>
#define kfileName @"dataTM.plist"
@interface SliderTestViewController : UIViewController {
IBOutlet UILabel *slider1Text;
IBOutlet UILabel *slider2Text;
IBOutlet UILabel *sliderTotal;
IBOutlet UISlider *slider01;
IBOutlet UISlider *slider02;
}
@property (nonatomic, retain) IBOutlet UILabel *slider1Text;
@property (nonatomic, retain) IBOutlet UILabel *slider2Text;
@property (nonatomic, retain) IBOutlet UILabel *sliderTotal;
@property (nonatomic, retain) IBOutlet UISlider *slider01;
@property (nonatomic, retain) IBOutlet UISlider *slider02;
- (IBAction) sliderChanged: (id) sender;
- (void)applicationWillTerminateNSNotification *)notification;
@end

.m file
#import "SliderTestViewController.h"
@implementation SliderTestViewController
@synthesize slider1Text;
@synthesize slider2Text;
@synthesize sliderTotal;
@synthesize slider01;
@synthesize slider02;
NSInteger sliderTag = 0;
NSInteger sliderValue = 0;
NSInteger sliderValueTotal = 0;
NSInteger slider1 = 0;
NSInteger slider2 = 0;

- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kfileName];
}

- (IBAction) sliderChanged: (id) sender {
UISlider *slider = (UISlider *) sender;
sliderTag = slider.tag;
sliderValue = (int)(slider.value + 0.5f);
if (sliderTag == 1) {
slider1Text.text = [NSString stringWithFormat:@"%i",sliderValue];
slider1 = sliderValue;
slider01.value = sliderValue;
slider01.tag = sliderTag;
}
if (sliderTag == 2) {
slider2Text.text = [NSString stringWithFormat:@"%i",sliderValue];
slider2 = sliderValue;
slider02.value = sliderValue;
slider02.tag = sliderTag;
}
sliderValueTotal = slider1 + slider2;
sliderTotal.text = [NSString stringWithFormat:@"%d total",sliderValueTotal];
}

- (void)applicationWillTerminateNSNotification *)notification {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:slider1Text.text];
[array addObject:slider2Text.text];
[array writeToFile:[self dataFilePath] atomically:YES];
[array release];

}
- (void)viewDidLoad {
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
slider1Text.text = [array objectAtIndex:0];
slider2Text.text = [array objectAtIndex:1];
[array release];
}
UIApplication *app = [UIApplication sharedApplication]; // get a reference to our application instance with sharedApplication
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate name:UIApplicationWillTerminateNotification object:app];
if(slider01.tag == 1) {
slider01.value = [slider1Text.text floatValue];
}
if (slider02.tag == 2) {
slider02.value = [slider2Text.text floatValue];
}
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
self.slider1Text = nil;
self.slider2Text = nil;
self.sliderTotal = nil;
self.slider01 = nil;
self.slider02 = nil;
}
- (void)dealloc {
[slider1Text release];
[slider2Text release];
[sliderTotal release];
[slider01 release];
[slider02 release];
[super dealloc];
}
@end

Last edited by maddams; 01-10-2010 at 08:37 PM.
maddams is offline   Reply With Quote
Old 01-10-2010, 08:38 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Bangkok / Koh Samui Thailand
Posts: 25
maddams is on a distinguished road
Default code fixed

code above works
maddams is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 337
14 members and 323 guests
akacaj, alexP, Domele, Duncan C, givensur, GraffitiCircus, JmayLive, michelle, NetGuru, NSString, Paul Slocum, Sloshmonster, soohyun, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0