0

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"]]];
}
Fabio
  • 3,015
  • 2
  • 29
  • 49
  • 1
    Doesn't sound like the default behaviour. Did you have any code in the ViewDidAppear method that overrides those properties? – Jeow Li Huan May 14 '13 at 14:58
  • You need to post some code for that first controller. Show how those properties are set. – rdelmar May 14 '13 at 15:03
  • code added to question. sry :p – Fabio May 14 '13 at 15:15
  • What values are disappearing? Where do you display these values? Are you doing anything in viewDidDisappear? I don't think you want to be adding all those subviews every time you come back to this tab. – rdelmar May 14 '13 at 15:25
  • Ok, sorry, problem fixed. It was not the values that were reseting, it was that n that was going back to 1 everytime the view loads (it is the number of cells on my UITableView and the parameter that I use for iterations), which would have almost the same effect as if everyone of those properties "reset", that's why I thought that was happening. Thanks for the help – Fabio May 14 '13 at 15:33

0 Answers0