#import "Untitled19ViewController.h"@implementation Untitled19ViewController/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*//*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}-(void)viewWillAppear:(BOOL)animated
{
float f=[[NSUserDefaults standardUserDefaults] floatForKey:@"slidervalue"];
slider.value=f;
NSLog(@"1");
}-(void)viewWillDisappear:(BOOL)animated
{
NSLog(@"2");
float f=slider.value;
[[NSUserDefaults standardUserDefaults] setFloat:f forKey:@"slidervalue"];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}@end
如果你要退出前干点什么的话,在applicationwillterminate中做事情
- (void)viewDidDisappear:(BOOL)animated 这两个的,因为视图控制器控制的视图没变,就算运行后打开应用程序出现的还是那个视图,退出到后台也一样。
调用的是这个- (void)applicationWillTerminate:(UIApplication *)application
{
NSLog(@"%@", NSStringFromSelector(_cmd));
}
in iOS 4.0 and later, this method is called instead of the applicationWillTerminate: method when the user quits an application that supports background execution. You should use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. You should also disable updates to your application’s user interface and avoid using some types of shared system resources (such as the user’s contacts database). It is also imperative that you avoid using OpenGL ES in the background.
- (void)applicationWillTerminate:(UIApplication *)application
{
}
也许是apple的问题吧。
在网上找到其它帖子,大概也是这样说的。
http://stackoverflow.com/questions/4289617/why-isnt-viewwilldisappear-or-viewdidappear-being-calledhttp://stackoverflow.com/questions/6583834/iphone-why-not-deallocate-in-viewwilldisappear-and-allocate-in-viewwillappear如果你的viewController是window上第一个加进去的;
那么退出应用程序,根本不会进入viewController的viewWillDisappear, 它的dealloc同样不会进去。
我在应用程序委托的dealloc打了断点一样不进去。但是,如果是在这个viewController的基础上,再加入新的viewController,那么新的viewController的
viewWillDisappear是会正常调用的。总结:可能是因为效率原因。第一个进去的viewController不做这样的处理,避免再次构造。