PDA

View Full Version : value message for UISlider not working properly




bjomu
Jun 23, 2008, 08:58 AM
Hello

When I'm trying to get the value of a UISlider Object, I always get the value 0.0, regardless, what the actual value is


-(IBAction)push: (id)sender // is called by pushing a Button
{
test = [slider value]; // Slider value should be 7.5

[label setText:[NSString stringWithFormat:@"%f",test]]; //label is an outlet to a label , 0.000 is printed out
}

When i type
test = 3.0;
instead of the value message, the correct value is printed out, so there has to be something wrong with the value property.

Another strange thing: when i want to "po test" in the console I get "Cannot access memory at address 0x0"

Edit: I forgot to say: test is a global float of my AppController class, of which the method push is part of.



Sbrocket
Jun 23, 2008, 10:35 AM
Did you set the minimumValue and maximumValue of the UISlider when you created it?

"po test" telling you "Cannot access memory at address 0x0" means you're trying to print something that is nil. How exactly did you declare test?

bjomu
Jun 23, 2008, 10:42 AM
Thanks for your answer.

Yes, the minimum value is 3.0 and maximum is 9.0. So 7.5 should work.
I did declae test in the interface part of the AppController.h file like this:

float test;

That's why it is so strange, that it is supposed to be nil.
I have the same problem, when i set the value directly like

test = 3;

Then there is the same "cannot access" error for po, but test is NOT nil, because the label prints the correct value.

I'm really confused, this kind of stuff works perfectly for normal cocoa coding , but not for cocoa touch.