iOS應(yīng)用開發(fā)實戰(zhàn)(7-9)-ViewController & Storyboard & AppLifecycle

這3節(jié)課互相關(guān)聯(lián)性較強(qiáng)钦铁,因此把筆記放一起了圣勒。
有關(guān)調(diào)試的內(nèi)容放在其它筆記里

MVC(Model-View-Controller)

是一種應(yīng)用程序設(shè)計框架

MVC.jpg
App Overview.png

補(bǔ)充閱讀:

https://en.wikipedia.org/wiki/Model–view–controller

主流設(shè)計模式簡介

主流設(shè)計模式.jpg

UIViewController

作用:

管理View的Controller

具體作用:

  • 管理View:鏈接占位
  • 傳遞數(shù)據(jù):鏈接占位
  • 響應(yīng)用戶操作:鏈接占位
  • 內(nèi)存管理钞护、狀態(tài)標(biāo)尺:鏈接占位
  • 適應(yīng)設(shè)備:鏈接占位

UIViewController示意圖

UIViewController.jpg

創(chuàng)建初始化界面

創(chuàng)建初始化界面.jpg

空界面圖示

空界面圖示.jpg

Tips:View debug的路徑,注意:需要先運(yùn)行模擬器

Capture View Hierarchy.png

View Controller Lifecycle

UIViewController Class Reference_2x.png

多View Controller常用方法和屬性

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion;

//View風(fēng)格
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle;

//風(fēng)格枚舉
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
            UIModalPresentationFullScreen = 0,
            UIModalPresentationPageSheet,
            UIModalPresentationFormSheet ,
            UIModalPresentationCurrentContext ,
            UIModalPresentationCustom ,
            UIModalPresentationOverFullScreen ,
            UIModalPresentationOverCurrentContext ,
            UIModalPresentationPopover ,
            UIModalPresentationNone  = -1,         
};

//動畫風(fēng)格
@property(nonatomic,assign) UIModalTransitionStyle modalTransitionStyle;

//風(fēng)格枚舉
typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
    UIModalTransitionStyleCoverVertical = 0,
    UIModalTransitionStyleFlipHorizontal,
    UIModalTransitionStyleCrossDissolve,
    UIModalTransitionStylePartialCurl ,
};
//顯示
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;

//撤銷
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion ;//全部撤銷,數(shù)據(jù)會丟失

UIViewController的屬性和方法一覽(占位)

- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecode;

@property(null_resettable, nonatomic,strong) UIView *view;
- (void)loadView;
- (void)loadViewIfNeeded;

@property(nullable, nonatomic, readonly, strong) UIView *viewIfLoaded;

- (void)viewDidLoad;
- (BOOL)isViewLoaded;

@property(nullable, nonatomic, readonly, copy) NSString *nibName;
@property(nullable, nonatomic, readonly, strong) NSBundle *nibBundle;
@property(nullable, nonatomic, readonly, strong) UIStoryboard *storyboard;

- (void)performSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender;
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender;
- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sende;
- (NSArray<UIViewController *> *)allowedChildViewControllersForUnwindingFromSource:(UIStoryboardUnwindSegueSource *)source;
- (nullable UIViewController *)childViewControllerContainingSegueSource:(UIStoryboardUnwindSegueSource *)source ;
- (void)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC;
- (void)viewWillAppear:(BOOL)animated;
- (void)viewDidAppear:(BOOL)animated;
- (void)viewWillDisappear:(BOOL)animated;
- (void)viewDidDisappear:(BOOL)animated;
- (void)viewWillLayoutSubviews;
- (void)viewDidLayoutSubviews;

@property(nullable, nonatomic,copy) NSString *title;
- (void)didReceiveMemoryWarning;

@property(nullable,nonatomic,weak,readonly) UIViewController *parentViewController;
@property(nullable, nonatomic,readonly) UIViewController *presentedViewController;
@property(nullable, nonatomic,readonly) UIViewController *presentingViewControlle;
@property(nonatomic,assign) BOOL definesPresentationContext;
@property(nonatomic,assign) BOOL providesPresentationContextTransitionStyle;

- (BOOL)isBeingPresented;
- (BOOL)isBeingDismissed;
- (BOOL)isMovingToParentViewController;
- (BOOL)isMovingFromParentViewController;
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion;
- (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion ;

@property(nonatomic,assign) UIModalTransitionStyle modalTransitionStyle;
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle;
@property(nonatomic,assign) BOOL modalPresentationCapturesStatusBarAppearance;

- (BOOL)disablesAutomaticKeyboardDismissal;

@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout;
@property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars;
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets;
@property (nonatomic) CGSize preferredContentSize;

- (UIStatusBarStyle)preferredStatusBarStyle
- (BOOL)prefersStatusBarHidden;
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation;
- (void)setNeedsStatusBarAppearanceUpdate ;
- (nullable UIViewController *)targetViewControllerForAction:(SEL)action sender:(nullable id)sender ;
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender;
- (void)showDetailViewController:(UIViewController *)vc sender:(nullable id)sender;

Demo:helloStoryBoard

helloStoryBoard.jpg

Storyboard Reference 位置

Storyboard Refa.png

跳轉(zhuǎn)和傳值

//跳轉(zhuǎn)
[self showViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"vc2"] sender:sender];

//用代碼執(zhí)行Segue
-(IBAction)actionWithSegue:(id)sender{
    [self performSegueWithIdentifier:@"go2" sender:sender];
}

//Go Scene 2
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
   if ([segue.identifier isEqualToString:@"go2"]) {    
        UIViewController *destination = segue.destinationViewController;      
        [destination setValue:_value forKey:@"value"];
    }
}
//后退到本Scene
-(IBAction)unwindToThisScene:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC{
 //判斷來源     
    if([unwindSegue.sourceViewController isKindOfClass:[secondViewController class]]){

        secondViewController *sc =(secondViewController *)unwindSegue.sourceViewController;
        _value = sc.value;
}
    else  if([unwindSegue.sourceViewController isKindOfClass:[ThirdViewController class]]){
 //       self.textField.text = nil;
    }
}

App Lifecycle

啟動

啟動.jpg

互動

互動.jpg

委托

委托.jpg

狀態(tài)切換

狀態(tài)切換.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末及穗,一起剝皮案震驚了整個濱河市肝箱,隨后出現(xiàn)的幾起案子哄褒,更是在濱河造成了極大的恐慌,老刑警劉巖煌张,帶你破解...
    沈念sama閱讀 206,378評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件呐赡,死亡現(xiàn)場離奇詭異,居然都是意外死亡骏融,警方通過查閱死者的電腦和手機(jī)链嘀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來档玻,“玉大人怀泊,你說我怎么就攤上這事∥笈浚” “怎么了霹琼?”我有些...
    開封第一講書人閱讀 152,702評論 0 342
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我枣申,道長售葡,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,259評論 1 279
  • 正文 為了忘掉前任忠藤,我火速辦了婚禮挟伙,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘模孩。我一直安慰自己像寒,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評論 5 371
  • 文/花漫 我一把揭開白布瓜贾。 她就那樣靜靜地躺著诺祸,像睡著了一般。 火紅的嫁衣襯著肌膚如雪祭芦。 梳的紋絲不亂的頭發(fā)上筷笨,一...
    開封第一講書人閱讀 49,036評論 1 285
  • 那天,我揣著相機(jī)與錄音龟劲,去河邊找鬼胃夏。 笑死,一個胖子當(dāng)著我的面吹牛昌跌,可吹牛的內(nèi)容都是我干的仰禀。 我是一名探鬼主播,決...
    沈念sama閱讀 38,349評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼蚕愤,長吁一口氣:“原來是場噩夢啊……” “哼答恶!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起萍诱,我...
    開封第一講書人閱讀 36,979評論 0 259
  • 序言:老撾萬榮一對情侶失蹤悬嗓,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后裕坊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體包竹,經(jīng)...
    沈念sama閱讀 43,469評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評論 2 323
  • 正文 我和宋清朗相戀三年籍凝,在試婚紗的時候發(fā)現(xiàn)自己被綠了周瞎。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,059評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡饵蒂,死狀恐怖声诸,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情苹享,我是刑警寧澤双絮,帶...
    沈念sama閱讀 33,703評論 4 323
  • 正文 年R本政府宣布浴麻,位于F島的核電站,受9級特大地震影響囤攀,放射性物質(zhì)發(fā)生泄漏软免。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評論 3 307
  • 文/蒙蒙 一焚挠、第九天 我趴在偏房一處隱蔽的房頂上張望膏萧。 院中可真熱鬧,春花似錦蝌衔、人聲如沸榛泛。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽曹锨。三九已至,卻和暖如春剃允,著一層夾襖步出監(jiān)牢的瞬間沛简,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評論 1 262
  • 我被黑心中介騙來泰國打工斥废, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留椒楣,地道東北人。 一個月前我還...
    沈念sama閱讀 45,501評論 2 354
  • 正文 我出身青樓牡肉,卻偏偏與公主長得像捧灰,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子统锤,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評論 2 345

推薦閱讀更多精彩內(nèi)容