#import <UIKit/UIKit.h> #import "DXWViewController1.h" @interface DXWViewController : UIViewController<DXWFlipsideViewControllerDelegate> - (IBAction)change:(id)sender; @property (retain, nonatomic) IBOutlet UILabel *label; @property (retain, nonatomic) IBOutlet UISwitch *switchButton; - (IBAction)showInfo:(id)sender; @end
#import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController -(void)viewWillAppear:(BOOL)animated { [self changeData]; } -(void)changeData { NSUserDefaults *usr = [NSUserDefaults standardUserDefaults]; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@YES,@"switch", nil]; [usr registerDefaults:dic]; ((UILabel *)self.label).text = [usr boolForKey:@"switch"]?@"开":@"关"; self.switchButton.on = [usr boolForKey:@"switch"]; //都要写入一下 [usr synchronize]; } - (void)viewDidLoad { [super viewDidLoad]; UIApplication *app = [UIApplication sharedApplication]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeData) name:UIApplicationWillEnterForegroundNotification object:app]; } - (void)dealloc { [self.switchButton release]; [_label release]; [super dealloc]; } //实现协议的方法 - (void)flipsideViewControllerDidFinish:(DXWViewController1 *)controller { [self dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)change:(id)sender { UISwitch *switchButton = sender; NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; [user setBool:switchButton.on forKey:@"switch"]; [user synchronize]; ((UILabel *)self.label).text = [user boolForKey:@"switch"]?@"开":@"关"; } - (IBAction)showInfo:(id)sender { UIStoryboard *strBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; DXWViewController1 *controller = [strBoard instantiateViewControllerWithIdentifier:@"DXWViewController1"]; controller.delegate = self; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:controller animated:YES completion:nil]; } @end
//连线的方法 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"Add"]) { DXWViewController1 *controlller = segue.destinationViewController; controlller.delegate = self; } }
#import <UIKit/UIKit.h> @class DXWViewController1; @protocol DXWFlipsideViewControllerDelegate - (void)flipsideViewControllerDidFinish:(DXWViewController1 *)controller; @end @interface DXWViewController1 : UIViewController @property (assign, nonatomic) id <DXWFlipsideViewControllerDelegate> delegate; - (IBAction)done:(id)sender; @end
#import "DXWViewController1.h" @interface DXWViewController1 () @end @implementation DXWViewController1 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)done:(id)sender { [self.delegate flipsideViewControllerDidFinish:self]; } @end
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。