Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
Hey guys I'm having a little trouble making a UISlider set a value.

here is my code:
Code:
 #define kGravity slide.value




-(IBAction)changeGrav {
	
	slide.value = kGravity;
	
}


Is there something that I'm doing wrong? I can't seem to get this to work.

Thanks and sorry for my elementary questions.
 

EnigMoiD

macrumors member
Aug 10, 2007
99
0
I'm not that familiar with #define, but it seems like you're using it wrong. You didn't give kGravity a data type, unless you defined it somewhere else. It should be a float between 0 and 1, I think. Just define it regularly.
Also, according to the Xcode documentation, you should use setValue:animated: to set the value, rather than changing the property manually.
What exactly did it do when you ran this code?
 

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
I'm not that familiar with #define, but it seems like you're using it wrong. You didn't give kGravity a data type, unless you defined it somewhere else. It should be a float between 0 and 1, I think. Just define it regularly.
Also, according to the Xcode documentation, you should use setValue:animated: to set the value, rather than changing the property manually.
What exactly did it do when you ran this code?

Nothing happens when i run it and change the slider value. It stays the same.
 

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
#define does a substitution. So, what you end up with is:
Code:
slide.value = slide.value;
That's not what you want.

So i should put a numerical value in the place of define?

so #define kGravity 4
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16)

Well, time to start debugging. What are the min and max values of your UISlider? Do you have slide properly connected? Any compile- or run-time errors? Etc.
 

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
the min and max values of my slider are 0 and 1. But kGravity is .432.

Yes, I have it in the Interface Builder, connected to the slider.

The thing is, when i try to move the slider, it locks up in one certain position, and then it wont move.

And there are no errors that make the project fail. Even when im running it, no errors. The only thing is the error mentioned above.

Thanks for all of the help!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
The thing is, when i try to move the slider, it locks up in one certain position, and then it wont move.
I would guess the certain position is the value .432. Why? Because, assuming changeGrav is connected to the valueChanged event of your slider, it's doing exactly what you're telling it to do: in response to a change in value, call changeGrav which then sets the slider's value to a constant, namely .432. Is there something else you want it to do?
 

PanzyCat

macrumors newbie
Original poster
Jul 7, 2010
21
0
I would guess the certain position is the value .432. Why? Because, assuming changeGrav is connected to the valueChanged event of your slider, it's doing exactly what you're telling it to do: in response to a change in value, call changeGrav which then sets the slider's value to a constant, namely .432. Is there something else you want it to do?

Yes, I want the user to be able to make the kGravity value whatever they wnat it to be.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Yes, I want the user to be able to make the kGravity value whatever they wnat it to be.
Then you need kGravity to be a variable and not a define. And you need to rearrange the pieces in your assignment statement.

Let me ask: what is your experience level with programming in Objective-C or programming in general?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.