我有一个UITabBarController
链接到 2 UIViewControllers
,并且在“第一个”UIViewController
中,当我切换到另一个视图控制器并返回时,我需要维护其值的属性。相反,每次我切换视图控制器时,这些属性的值都会被重置。我该如何解决?谢谢!
编辑:
这是我的代码UIViewController
(滚动视图位于除标签栏和顶部的导航栏之外的所有内容):
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"]]];
}