0

The answer in this question was helpful to me (and I up-voted it) in understanding how to retrieve the stepper value in the IBAction method, but I am still not understanding how to get the initial value of the stepper when I first load the view.

I want to set the initial value to 1 so in IB attributes I set Stepper Current (and Minimum) to 1. and then in viewDidLoad set my label outlet as follows:

 self.label.text = [NSString stringWithFormat:@"%d", stepper.value];

but when the view displays, the label displays a value of 0 and when I NSLog to examine stepper.value the debugger shows (null).

I get, I think, that I need to somehow instantiate the UIStepper object at this point but I need to understand how to retrieve the initial stepper value.

Community
  • 1
  • 1
larick
  • 259
  • 5
  • 12

2 Answers2

4

Check if stepper equals nil in that method. Perhaps you didn't set up your IBOutlet properly?

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83
  • I've added the check and yes stepper == nil at that point. I'm pretty sure the outlet is set properly ('label' is connected to File's Owner in the Connections inspector) as when I call the action method and click the stepper control the label field is updating according to the values set in the stepper's attribute inspector. – larick Nov 02 '11 at 20:32
  • 2
    You have to make 2 connections with the stepper. One as an outlet and another as an action. Your comment implies the action is definitely set, but the outlet may not be. Then you might run into the situation where using %1.0f helps. – Jesse Black Nov 02 '11 at 20:48
  • OK. I had the action outlet set but not the outlet was not. That solved it. Thanks. – larick Nov 02 '11 at 20:53
1

I tested this with a UIStepper and logging. When I log with %d it outputs 0, when I log with %1.0f it outputs 1

Try this

self.label.text = [NSString stringWithFormat:@"%1.0f", stepper.value];

I suggest this because the property value is a double

According to your comment under Alexsander Akers' answer you should ensure the outlet is set.

Jesse Black
  • 7,966
  • 3
  • 34
  • 45