This is the code from the class within which I am trying to reference the properties from the other class(BIDDoubleComponentPickerViewController):
BIDDoubleComponentPickerViewController *dummyObject = [BIDDoubleComponentPickerViewController new];
NSString *selectedValue = [dummyObject value];
NSString *selectedSuit = [dummyObject suit];
However, whenever I attempt to access the variables selectedValue and selectedSuit, they claim that they are null, when I know for a fact that value and suit are not null within the other class. Here is the code that sets the properties in BIDDoubleComponentPickerViewController:
NSInteger valueRow = [doublePicker selectedRowInComponent:
kValueComponent];
NSInteger suitRow = [doublePicker selectedRowInComponent:
kSuitComponent];
value=[[NSString alloc]initWithString:[values objectAtIndex:valueRow]];
suit=[[NSString alloc]initWithString:[suits objectAtIndex:suitRow]];
Here is the code for the declaration of the properties:
@property (strong, nonatomic) NSString *value;
@property (strong, nonatomic) NSString *suit;
Anyone have any ideas?
When you create a new view controller, it doesn’t load its view immediately. So if the code where you initialize
valueandsuitis located in theinitmethod, thendoublePickeris stillnil. Otherwise, if that code is located inviewDidLoadorloadView, then it is still not executed when you try to accessvalueandsuitusing[dummyObject value];and[dummyObject suit];Edit: (After OP’s comment)
My answer is still correct because in the line:
you create a new object
dummyObjectthat is different from the view controller where the picker view was visible. So the valuesvalueandsuitthat you are looking for are properties of the other view controller and not the one you just initialized.To solve your problem, you should not create a new instance of
BIDDoubleComponentPickerViewControllerbut retrieve the instance that holds the values you are looking for.