I usually make headers like this:
#import <UIKit/UIKit.h>
@interface SettingsViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
@property (nonatomic, weak) IBOutlet UITextField *userTextField;
@property (nonatomic, weak) IBOutlet UITextField *passwordTextField;
@property (nonatomic, strong) IBOutlet UIPickerView *elementPicker; // I would suggest to use sttong for outlets if you are planning to move them out of their superview
//@property (nonatomic, retain) NSMutableArray *elements; // if you use ARC I would suggest to forget about retain in favor of strong.
@property (nonatomic, strong) NSMutableArray *elements;
//@property NSString *elements2; // I would suggest not to rely on implicit property specifier declarations in favor of more verbosity
@property (nonatomic, strong) NSString *elements2;
- (IBAction)userOrPasswordChanged:(id)sender;
@end
Then in .h or .m file you don't need to declare _elements
(or elements
) one more time since it is automatically created with property declaration. If you need to declare it (it is needed in some cases) you should be careful and read about naming convention.
With such header the original questions problem should be solved unless you do something extravagant in your remaining code.
EDIT: I have dug a bit in topic starter's real code. The problem is that he has 2 instances of SettingsViewController. They are both set in his storyboard.
so one of the instances is used to be presented to screen and thus viewDidLoad
method is called and _elements
is populated and another is created silently by storyboard and used as the instance used as datasource and delegate of UIPickerView. The second instance is not shown so its viewDidLoad
method is not called and _elements
are nil.
So if you print self
along with elements
you will see the difference.
If you remove the second instance in the picture you will get everything working.