How to use the UIStepper to control global variable?

Wesily0331

I tried to control the num variable through UIStepper, but when I pressed the increase button,

It always start count from 0 not 10,

I am curious what did I miss in my code,

Thank you in advance for any comments

#import "ViewController.h"

int num = 10;

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *myLabel;
- (IBAction)myStepper:(UIStepper *)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _myLabel.text = [NSString stringWithFormat:@"%i", num];
}

- (IBAction)myStepper:(UIStepper *)sender {
    num = [sender value];
    _myLabel.text = [NSString stringWithFormat:@"%i", num];
}
@end
Zev Eisenberg

You're never setting the value of the stepper to num. Either set it in Interface Builder's Attributes Inspector, or create an outlet to your stepper:

@property (weak, nonatomic) IBOutlet UIStepper myStepper;

And then in -viewDidLoad, set it like this:

self.myStepper.value = num

As an aside, I would recommend against using a global variable. I would make a property for num instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to declare a variable for global use

From Dev

How to use Global Variable in Python

From Dev

How to use the value of a global variable?

From Dev

How to use the value of a global variable to determine the control flow of a function running in separate thread?

From Dev

How to use global variable in PHP Codeigniter

From Dev

How to create and use a global variable on Mule config?

From Dev

How to use AsyncTask to update a global variable

From Dev

How to define a global variable in LLVM and use it in C?

From Dev

How to use global variable in symfony twig file?

From Dev

How to create and use a global variable on Mule config?

From Dev

How to use AsyncTask to update a global variable

From Dev

How to use sharedInstance on swift as global variable?

From Dev

How to create a global variable and use it in other pages?

From Dev

how to use a global variable inside a function in javascript?

From Dev

How to use global variable in onClick() method?

From Dev

How to use a class attribute instead of a global variable?

From Dev

How to use the global variable to initialize the class property?

From Dev

How to use a datatrigger that needs a static global variable?

From Dev

iOS UIStepper & NSUserDefaults - How to manage them together and use a double

From Dev

How to use a variable in referencing the name of a control

From Dev

Global variable use

From Dev

Global variable use case

From Dev

use shuffelArray as global variable

From Dev

How to use Powershell global variable inside CMD.EXE statement

From Dev

How to use a global variable in an array index using Handlebars

From Dev

How do I use a global variable in unit testing?

From Dev

html/javascript/php: how do i use a "global variable"?

From Dev

How to Assign value to global variable and use it in other functions in jquery/javascript?

From Dev

How to use global variable inside do_shortcode

Related Related

  1. 1

    How to declare a variable for global use

  2. 2

    How to use Global Variable in Python

  3. 3

    How to use the value of a global variable?

  4. 4

    How to use the value of a global variable to determine the control flow of a function running in separate thread?

  5. 5

    How to use global variable in PHP Codeigniter

  6. 6

    How to create and use a global variable on Mule config?

  7. 7

    How to use AsyncTask to update a global variable

  8. 8

    How to define a global variable in LLVM and use it in C?

  9. 9

    How to use global variable in symfony twig file?

  10. 10

    How to create and use a global variable on Mule config?

  11. 11

    How to use AsyncTask to update a global variable

  12. 12

    How to use sharedInstance on swift as global variable?

  13. 13

    How to create a global variable and use it in other pages?

  14. 14

    how to use a global variable inside a function in javascript?

  15. 15

    How to use global variable in onClick() method?

  16. 16

    How to use a class attribute instead of a global variable?

  17. 17

    How to use the global variable to initialize the class property?

  18. 18

    How to use a datatrigger that needs a static global variable?

  19. 19

    iOS UIStepper & NSUserDefaults - How to manage them together and use a double

  20. 20

    How to use a variable in referencing the name of a control

  21. 21

    Global variable use

  22. 22

    Global variable use case

  23. 23

    use shuffelArray as global variable

  24. 24

    How to use Powershell global variable inside CMD.EXE statement

  25. 25

    How to use a global variable in an array index using Handlebars

  26. 26

    How do I use a global variable in unit testing?

  27. 27

    html/javascript/php: how do i use a "global variable"?

  28. 28

    How to Assign value to global variable and use it in other functions in jquery/javascript?

  29. 29

    How to use global variable inside do_shortcode

HotTag

Archive