synthesize this fridgeManager property in IngredientViewController.m
@synthesize fridgeManager;
Domanda
I'm trying to get IngredientViewController
to update an array belongs to the controller that called it via the segue (FridgeViewController
)
In IngredientViewController
fridgeManager is nil no matter what I try
The code:
FridgeViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
IngredientViewController *controller = (IngredientViewController *)segue.destinationViewController;
[controller setFridgeManager:fridgeManager];
}
IngredientViewController:
@property (strong, nonatomic) FridgeDataManager *fridgeManager;
and in viewDidLoad fridgeManager
is nil (and in any other method of coarse)
Soluzione
synthesize this fridgeManager property in IngredientViewController.m
@synthesize fridgeManager;
Altri suggerimenti
In newer versions of Xcode, you don't need to synthesize your properties, OR create an instance variable. If you don't do either, then Xcode creates an instance variable with a "_" prefix to match your property. (I believe this was is a change that was part of Objective C 2.0.)
So
@property (nonatomic, strong) NSString *foo;
Gives you an instance variable of `_foo.
And you could use it like:
[controller setFridgeManager: _foo];
If you have both a property fridgeManager and an instance variable fridgeManager, they are likely different entities, so setting
fridgeManager = x;
Would change a different instance variable than setting
self.fridgeManager = x;