您好,登錄后才能下訂單哦!
#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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。