Header Files: SettingsVC.h ViewController.h
Implementation Files: SettingsVC.m ViewController.m
In ViewController.m, I imported SettingsVC.h using this line of code at the top
import “SettingsVC.h”
so I can obtain a value from a stepper from a different view.
In SettingsVC.h I have a line of code that says IBOutlet UIStepper *mainStepper;
that is assigned to a stepper.
When I try to access the value of the stepper from the ViewController.m by doing this mainStepper.value it doesn’t work but it works in the Settings.m Thanks for any help.
New stuff for Vikings
SettingsVC.h FILE
#import <UIKit/UIKit.h>
@interface SettingsVC : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
IBOutlet UILabel *mainTimeShow;
IBOutlet UILabel *armTimeShow;
IBOutlet UILabel *defuseTimeShow;
IBOutlet UIStepper *armStepper;
IBOutlet UIStepper *defuseStepper;
IBOutlet UIStepper *mainStepper;
}
-(IBAction)goToClock;
@property (nonatomic, retain) UIStepper *mainStepper;
-(IBAction)mainTimeStepper;
-(IBAction)armTimeStepper;
-(IBAction)defuseTimeStepper;
@end
SettingsVC.m FILE
#import "SettingsVC.h"
@interface SettingsVC ()
@end
@implementation SettingsVC
@synthesize mainStepper;
@end
ViewController.m FILE
#import "ViewController.h"
#import "SettingsVC.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)here {
SettingsVC.mainStepper.value; //Property mainStepper not found on object of type 'SettingsVC'
}
@end
I edited my answer, and this should make everything clear. You only create the UIStepper in one class, in this case SettingsVC. Then you can retrieve the variable through the property in other classes, just import SettingsVC.
You need to create the property in SettingsVC.h
You need to synthesize the property in SettingsVC.m
Let’s say you have a class named ViewController. You would access the value of the UIStepper like such:
You will be using this in other classes, so you need to retain this property. You typically only use assign with primitive values such as a BOOL.
Edit: ARC will will automatically release settingsVC for you, so never explicitly release.