I have a UITabBarController
linked to 2 UIViewControllers
, and in the "first" UIViewController
I have properties whose values I need to be maintained when I switch to the other view controller and back. Instead, the value of those properties is reset every time I switch view controllers. How do I fix that? thanks!
EDIT:
heres my code in the UIViewController
(the scrollview is under everything but the tab bar and a navigation bar I have on top):
SplitBillViewController.m
@interface SplitBillViewController ()
@property (nonatomic) NSMutableArray *defPricesArray;
@property (nonatomic) NSMutableArray *defQtyArray;
@property (nonatomic) NSMutableArray *defTickArray;
@property (nonatomic) NSMutableArray *defPeopleArray;
@end
@implementation SplitBillViewController
- (void)viewDidLoad{
[super viewDidLoad];
}
-(NSMutableArray *)defPeopleArray{
if(!_defPeopleArray){
_defPeopleArray=[[NSMutableArray alloc] initWithObjects:@"1", nil];
}
return _defPeopleArray;
}
-(NSMutableArray *)defQtyArray{
if(!_defQtyArray){
_defQtyArray=[[NSMutableArray alloc] initWithObjects:@"1", nil];
}
return _defQtyArray;
}
-(NSMutableArray *)defPricesArray{
if(!_defPricesArray){
_defPricesArray=[[NSMutableArray alloc] initWithObjects:@"0.00", nil];
}
return _defPricesArray;
}
-(NSMutableArray *)defTickArray{
if(!_defTickArray){
_defTickArray = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:1], nil];
}
return _defTickArray;
}
-(void)viewWillAppear:(BOOL)animated{
n=1;
aid=@"";
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissTipPercentage)];
[self.view addGestureRecognizer:tap];
if (iPhone5){
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"background-568h"]];
}
else {
self.view.backgroundColor = [UIColor blackColor];
}
[self.scrollView addSubview:self.itemTable];
[self.scrollView addSubview:self.totalValue];
[self.scrollView addSubview:self.tip];
[self.scrollView addSubview:self.tipPercentage];
[self.scrollView addSubview:self.addedValue];
[self.scrollView addSubview:self.perPerson];
self.scrollView.alpha=1;
if (!iPhone5)[self.scrollView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"ScrollViewBackground"]]];
else [self.scrollView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"ScrollViewBackground-568h"]]];
}