在viewDidLoad 中构建视图,因此您只需添加一次控件,但在viewWillShow 中刷新。请记住,viewWillShow 将在viewDidLoad 完成构建后立即刷新它。因此,将定义控件外观的值保留在第一个 viewController 上,例如,在委托可变数组中
例如在您的 AppDelegate.h 和 .m
中创建并启动
NSMutableArray
在.h界面中
NSMutableArray *yourArray;
添加属性
@property (retain, nonatomic) NSMutableArray *yourArray;
在.m
@synthesyze yourArray;
在 .m 中启动它
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
yourArray=[[NSMutableArray alloc]init];
//add initial objects to it as many as you have controls
}
在第一viewController
#import "AppDelegate.h"
-(void)viewWillShow:(BOOL)animated{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//pull objects from array and apply to your controls, say you have a string as a 1st obj
NSString *tmpStr=[appDelegate.yourArray objectAtIndex:0];//use it some where, say button's title
//etc
}
您将根据用户的选择在第二个viewController 中更改这些值
#import "AppDelegate.h"
在第二个viewController 的某处,yourArray 中的代码更新值在
上说
-(void)viewWillDisappear:(BOOL)animated{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//run a loop and update all objects
[appDelegate.yourArray replaceObjectAtIndex:i withObject:newObj];
}
当您返回第一个viewController 时,viewWillShow 将从您的委托数组中刷新它们。