中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

[IOS]Setting Bundle + StoryBoard

發布時間:2020-08-09 18:36:58 來源:網絡 閱讀:342 作者:蓬萊仙羽 欄目:移動開發

用storyboard添加一個導航欄,其中首頁有一個switch,與setting聯動,還有一個button,使用modal連接另一個viewControl,其上也有一個按鈕,按下銷毀本viewControl,回到前一頁。

實現步驟:

1.創建一個SingleView的項目,勾選上storyboard。

2.向storyboard中添加一個NavigationController,兩個ViewController,然后在NavigationController中右擊指向第一個ViewController,然后設置為rootViewController,并且將箭頭指向NavigationController。

3.將兩個ViewController的Class分別設置為DXWViewController和DXWViewController1(兩個自己創建的類,繼承自ViewController)

4.創建setting文件,并將root.plist保存一個鍵值對,key改成switch

5.修改DXWViewController(主視圖)

[IOS]Setting Bundle + StoryBoard

DXWViewController.h:

#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

DXWViewController.m:

#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


上圖中showInfo方法是通過代碼的方法實現跳轉到下一個view,如果是通過storyboard實現連線的方法然后跳過下一個view是這樣實現:

@“Add”是連線的ID
//連線的方法 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {     if ([segue.identifier isEqualToString:@"Add"]) {         DXWViewController1 *controlller = segue.destinationViewController;         controlller.delegate = self;     } }


6.修改DXWViewController1(子視圖)

[IOS]Setting Bundle + StoryBoard

DXWViewController.h:

#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

DXWViewController.m:

#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




向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

红原县| 蛟河市| 通道| 进贤县| 同仁县| 禄丰县| 安多县| 田阳县| 梅州市| 方城县| 棋牌| 儋州市| 密山市| 土默特右旗| 乳源| 武宣县| 吴桥县| 盐津县| 凤山市| 腾冲县| 望都县| 罗江县| 合山市| 泽普县| 光泽县| 宣恩县| 昌宁县| 潞西市| 鹤山市| 民勤县| 金川县| 潮州市| 兴仁县| 沐川县| 永川市| 汉川市| 通辽市| 新和县| 寿光市| 鹤峰县| 桑日县|