I feel ignorant for asking this because I know it's simple. Goal: Retain a variable on a view after leave then returning to it.
For instance: Let's say we have MainView, CategoryView and (drumroll) ProjectView
Application opens to MainView it displays a table - user selects they want to pick a category. This segue's them to CategoryView. Once a selection is made I send the chosen category back to MainView. via
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
No problem here. MainView receives variable and displays the chosen category as subtext in the 'Category' section. Next the user wants to pick a project name (this is also a predefined list) They select the item and I send the variable back the MainView.
-- Now can somebody explain to me (gently) why when I return to the main view the NSString variable that was previously holding the 'chosen' category is now null?
So my NSString selectedProject is not being retained correct? What is the correct implementation I should be doing here? Or what am I missing? I'm really trying to understand whats going on so anything would be a great help.
MainView Interface
@interface MainViewController : UIViewController {
NSString *selectedProjectName;
NSString *selectedCategory;
}
@property (nonatomic, retain) NSString *selectedProjectName;
@property (nonatomic, retain) NSString *selectedCategory;
@end
MainView Implementation
@implementation MainViewController
@synthesize selectedCategory, selectedProjectName;
and if you need it.. ProjectView Implementation
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"masterSegue"]) {
MainViewController *vc = (MainViewController *)[segue destinationViewController];
LogValues *lv = [LogValues alloc];
lv.project = @"Test Project Name";
vc.selectedProjectName = lv.project;
}
}