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 08-13-2010, 02:57 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default Get UISlider Value from different view.

Hey guys.
Can anyone tell me a simple way on how to get a slider value from view A into view B. Please provide some code. Thanks to anyone who attempts to answer my question!
Yves is offline   Reply With Quote
Old 08-13-2010, 04:13 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Hey guys.
Can anyone tell me a simple way on how to get a slider value from view A into view B. Please provide some code. Thanks to anyone who attempts to answer my question!
Does View B launch view A? (Modally or push onto stack?)

See this answer of mine which may be similar... It is about popovers on iPad but the concepts apply.
https://devforums.apple.com/thread/63458?tstart=50

Last edited by Ladd; 08-13-2010 at 04:17 PM.
Ladd is offline   Reply With Quote
Old 08-13-2010, 04:29 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default Thanks for your reply!

Hey, thanks so much for your reply. So up to now i have had 2 different .h view controllers with 2 xib's. I used the info button to switch between them. In the second view i want to have volume control sliders that will set the volume of the music in the first view. So i would i have do this data sharing thing which my brain wont get.Now I have read about subviews.Would creating a subview solve the problem? And if so, how do i create a subview?
Thanks again.
Yves is offline   Reply With Quote
Old 08-13-2010, 04:31 PM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Hey, thanks so much for your reply. So up to now i have had 2 different .h view controllers with 2 xib's. I used the info button to switch between them. In the second view i want to have volume control sliders that will set the volume of the music in the first view. So i would i have do this data sharing thing which my brain wont get.Now I have read about subviews.Would creating a subview solve the problem? And if so, how do i create a subview?
Thanks again.
So you are using the Utility App template?

And no... SubView is not the answer IMHO...

Last edited by Ladd; 08-13-2010 at 04:34 PM.
Ladd is offline   Reply With Quote
Old 08-13-2010, 04:34 PM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Nope its a view based application .
Yves is offline   Reply With Quote
Old 08-13-2010, 04:42 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Nope its a view based application .
Well... How are you bringing the second view up? Modally? Animated transition?

When the info button is clicked you bring up that next view. Make the view that HAS the info button the delegate of the next one. When the slider changes call the procedure back in the first view and change the volume... You can pass the slider value back in that procedure.. (If you look at the code posted it should make sense...)

Like:
Code:
@protocol AddColorViewControllerDelegate
- (void)addDisplayViewControllerDidFinish:(AddColorViewController *)controller:(NSString *)YvesSliderVariable;
@end
Code:
[self.delegate addDisplayViewControllerDidFinish:self:sliderValue];
Hope that helps some...
Ladd is offline   Reply With Quote
Old 08-13-2010, 04:53 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Overkill m8. So the first code u posted sets View A as the delegate of View B. Then the next code you posted is how u callback the value while in View A from View B? Sorry im a bloody beginner and thanks a ton for your patience.
Yves is offline   Reply With Quote
Old 08-13-2010, 04:55 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Oh btw its an animated transition. Also where do i place the @protocol in my code? in the header file of the first view controller?
Yves is offline   Reply With Quote
Old 08-13-2010, 04:59 PM   #9 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

It might make more sense if you try this:

Create a new project from the Utility App template.

Place this statement n the following procedures:
NSLog(@"Entering >>> %s", __PRETTY_FUNCTION__);

MainViewController.m:
Code:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
- (IBAction)showInfo:(id)sender
FlipSideViewController.m
Code:
- (IBAction)done:(id)sender
Now go back and forth... You will see that the procedure in Main gets called when FlipSide Done is clicked... Pass what ever you want to that procedure.

You can also pass things to FlipSide Like this:
Code:
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.YvesFlipSideVariable = "@Sweet" //Needs to be declared in Flip and I know the Capital Y is not convention... Making a point!
This is a recommend approach by Apple. (see my links in previous post reference)


Ladd

Last edited by Ladd; 08-13-2010 at 05:06 PM.
Ladd is offline   Reply With Quote
Old 08-13-2010, 05:00 PM   #10 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Oh btw its an animated transition. Also where do i place the @protocol in my code? in the header file of the first view controller?
Study the FlipSideViewController and MainViewController .h files in the template. The lightbulb WILL go off...

Ladd is offline   Reply With Quote
Old 08-13-2010, 05:07 PM   #11 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Ok Master i shall report back to you (even if u don't care ) once i succeed!
Yves is offline   Reply With Quote
Old 08-13-2010, 05:13 PM   #12 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Ok Master i shall report back to you (even if u don't care ) once i succeed!
Cracking Up... I'm no master... Maybe a belt or two above white or yellow or whatever.

It took a lot of patience, trial and ERROR before It made sense to me... Now it does and it works well.

Let me know if does for you. I would like to hear back.

Good luck with it!!!


Ladd
Ladd is offline   Reply With Quote
Old 08-13-2010, 05:29 PM   #13 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Yves... You a Kiwi by chance?
Ladd is offline   Reply With Quote
Old 08-13-2010, 06:40 PM   #14 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

LOL A Kiwi? as in the fruit? I don't know...Im on my 15th attempt right now, so yes i'm actually beginning to wonder myself if i am in fact a kiwi. Wanna eat me-----my life is not worth living anymore ?
Yves is offline   Reply With Quote
Old 08-13-2010, 06:52 PM   #15 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
LOL A Kiwi? as in the fruit? I don't know...Im on my 15th attempt right now, so yes i'm actually beginning to wonder myself if i am in fact a kiwi. Wanna eat me-----my life is not worth living anymore ?
Cracking Up again... No a New Zealander. (m8, Bloody - Hadn't heard that much since my Kiwi friends)

Still laughing!!!
Ladd is offline   Reply With Quote
Old 08-13-2010, 06:57 PM   #16 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

nah lol, it comes from all the video games i have played .
Yves is offline   Reply With Quote
Old 08-13-2010, 06:59 PM   #17 (permalink)
Registered Member
 
stoicjustice's Avatar
 
Join Date: Jun 2010
Posts: 25
stoicjustice is on a distinguished road
Default

You could always save the UISlider value as an NSUserDefaults variable. For example, wherever your slider is, put in this code:

Code:
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:sliderValue forKey:"slider"];
sliderValue is obviously an NSString or NSInteger for your slider.value.

Then, in whatever view of your application that you want to call that variable back, just insert the code:

Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *newValue = [[NSString alloc]init];
newValue = [defaults stringForKey:"slider"];
That should work. I have found that NSUserDefaults is very convenient for data persistence throughout an application.

NOTE: If for some reason you decide to save your slider value as an Integer instead of a string, make sure to use 'integerForKey' instead of 'stringForKey'. Also, make sure to release those new strings you allocate - be a good memory citizen.
__________________
Army APFT App - http://bit.ly/d9dINL
APFT Pro website - www.apftpro.weebly.com
My current project - www.ncoforms.com
stoicjustice is offline   Reply With Quote
Old 08-13-2010, 07:03 PM   #18 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Master Ladd dont worry i am still loyal to you, but i will have attempt stoicejustices wise approach to this problem.
Yves is offline   Reply With Quote
Old 08-13-2010, 07:13 PM   #19 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Quote:
Originally Posted by stoicjustice View Post
You could always save the UISlider value as an NSUserDefaults variable. For example, wherever your slider is, put in this code:

Code:
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:sliderValue forKey:"slider"];
sliderValue is obviously an NSString or NSInteger for your slider.value.

Then, in whatever view of your application that you want to call that variable back, just insert the code:

Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *newValue = [[NSString alloc]init];
newValue = [defaults stringForKey:"slider"];
That should work. I have found that NSUserDefaults is very convenient for data persistence throughout an application.

NOTE: If for some reason you decide to save your slider value as an Integer instead of a string, make sure to use 'integerForKey' instead of 'stringForKey'. Also, make sure to release those new strings you allocate - be a good memory citizen.
Thnx alot.
So i put the NSUserDefaults in my IBAction for the slider and it gives me error message my not respond to set object stringforkey and when i interact with the slider the app crashes.
please help me and thnx again.
Yves is offline   Reply With Quote
Old 08-13-2010, 07:13 PM   #20 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by Yves View Post
Master Ladd dont worry i am still loyal to you, but i will have attempt stoicejustices wise approach to this problem.
LOL... No worries (<<< Kiwi Friends remember?) I don't have all the answers.

But
Code:
in whatever view of your application that you want to call that variable back
Means your Volume slider won't register your volume changes until you return to the view. Based on your OP you want that to happen kinda "live"... Right?

Call the delegate method as it changes and it will/can. Maybe add a little delay to smooth it out... Dunno

And the below is from other code... But you should get the jist.
Code:
- (IBAction)sliderChanged:(id)sender
{
	//NSLog(@"Entering >>> %s", __PRETTY_FUNCTION__);
	
	UISlider* usedSlider = (UISlider *)sender;
	
	float answer = 0.0;
	int quarters = 0.0;
	
	
	if (usedSlider.value < 0.25) {
		answer = 0.10;
	}
	else {
		quarters = (int)(usedSlider.value * 4 + 0.25);
		answer = quarters * 0.25;
	}

	
	
	//quarters = (int)(usedSlider.value * 4 + 0.25);
	//answer = quarters * 0.25;
	
	
	if(usedSlider == speedSlider)
	{
		//NSLog(@"It is the speedSlider slider");		
		
		self.speedTextField.text = [NSString stringWithFormat:@"%.2f", answer];
		self.speed = [NSString stringWithFormat:@"%.2f", answer];	
		
	}
	
	[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(callMyDelegate) object:nil];
	[self performSelector:@selector(callMyDelegate) withObject:nil afterDelay:.2];
	
	
}



- (void)callMyDelegate
{
	//NSLog(@"Entering >>> %s", __PRETTY_FUNCTION__);		
	[self.delegate didFinish:self:speed];
}
It is all fun learning...


Ladd

Last edited by Ladd; 08-13-2010 at 07:18 PM.
Ladd is offline   Reply With Quote
Old 08-13-2010, 07:15 PM   #21 (permalink)
Registered Member
 
stoicjustice's Avatar
 
Join Date: Jun 2010
Posts: 25
stoicjustice is on a distinguished road
Default

Could you post the code for the 2 places you are trying to utilize the code? (Both where you are saving it and where you are loading it)
__________________
Army APFT App - http://bit.ly/d9dINL
APFT Pro website - www.apftpro.weebly.com
My current project - www.ncoforms.com
stoicjustice is offline   Reply With Quote
Old 08-13-2010, 07:18 PM   #22 (permalink)
Registered Member
 
stoicjustice's Avatar
 
Join Date: Jun 2010
Posts: 25
stoicjustice is on a distinguished road
Default

Quote:
Originally Posted by Ladd View Post
LOL... No worries (<<< Kiwi Friends remember?) I don't have all the answers.

But
Code:
in whatever view of your application that you want to call that variable back
Means your Volume slider won't register your volume changes until you return to the view. Based on your OP you want that to happen kinda "live"... Right?

Call the delegate method as it changes and it will/can. Maybe add a little delay to smooth it out... Dunno

Code:
- (IBAction)sliderChanged:(id)sender
{
	//NSLog(@"Entering >>> %s", __PRETTY_FUNCTION__);
	
	UISlider* usedSlider = (UISlider *)sender;
	
	float answer = 0.0;
	int quarters = 0.0;
	
	
	if (usedSlider.value < 0.25) {
		answer = 0.10;
	}
	else {
		quarters = (int)(usedSlider.value * 4 + 0.25);
		answer = quarters * 0.25;
	}

	
	
	//quarters = (int)(usedSlider.value * 4 + 0.25);
	//answer = quarters * 0.25;
	
	
	if(usedSlider == speedSlider)
	{
		//NSLog(@"It is the speedSlider slider");		
		
		self.speedTextField.text = [NSString stringWithFormat:@"%.2f", answer];
		self.speed = [NSString stringWithFormat:@"%.2f", answer];	
		
	}
	
	[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(callMyDelegate) object:nil];
	[self performSelector:@selector(callMyDelegate) withObject:nil afterDelay:.2];
	
	
}



- (void)callMyDelegate
{
	//NSLog(@"Entering >>> %s", __PRETTY_FUNCTION__);		
	[self.delegate didFinish:self:speed];
}
It is all fun learning...


Ladd
It should be fairly instantaneous if he adds:
Code:
[defaults synchronize];
to the saving code and then loads it in the 'viewDidLoad' portion of whatever view he is transferring it to.
__________________
Army APFT App - http://bit.ly/d9dINL
APFT Pro website - www.apftpro.weebly.com
My current project - www.ncoforms.com
stoicjustice is offline   Reply With Quote
Old 08-13-2010, 07:26 PM   #23 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Ok so from the beginning i am making a drum app and when i click the info button it changes views and then from that view i want to control the volume for each drum. It dose not have to be activated until i change view again. Also i would like it to stay that way so next time when i change view the slider are where i left them.

Ok so if want me to post code i don't really have any....My flipsideview is still empty. All i did so far was create a practice app and i connected an IBOutlet to a slider and an IBAction changevalue. So i would be incredibly thankful if you could baby-feed me what i have to do.
Yves is offline   Reply With Quote
Old 08-13-2010, 07:29 PM   #24 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 146
Yves is on a distinguished road
Default

Sorry for my grammatical retardation, its to 2:30am where i live.
Yves is offline   Reply With Quote
Old 08-13-2010, 07:30 PM   #25 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Atlanta, GA
Posts: 16
Ladd is on a distinguished road
Default

Quote:
Originally Posted by stoicjustice View Post
It should be fairly instantaneous if he adds:
Code:
[defaults synchronize];
to the saving code and then loads it in the 'viewDidLoad' portion of whatever view he is transferring it to.
But viewDidLoad will only be called once. viewWillAppear will be called every time the view is shown. (in most instances... There are exceptions)

As I said. He wants a slider to control volume. That means he needs the changes sent to the "calling" view pretty much in real time. You can't wait for viewWillAppear. (and it won't be called in all circumstances)

Try both approaches...

Multiple options are always good. And it is nice that people contribute to help.

The delegate method is what Apple is pushing. And it works. Beautifully.

Ladd is offline   Reply With Quote
Reply

Bookmarks

Tags
data, sharing, uislider, views

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: 345
5 members and 340 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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