這3節(jié)課互相關(guān)聯(lián)性較強(qiáng)钦铁,因此把筆記放一起了圣勒。
有關(guān)調(diào)試的內(nèi)容放在其它筆記里
MVC(Model-View-Controller)
是一種應(yīng)用程序設(shè)計框架
補(bǔ)充閱讀:
https://en.wikipedia.org/wiki/Model–view–controller
主流設(shè)計模式簡介
UIViewController
作用:
管理View的Controller
具體作用:
- 管理View:鏈接占位
- 傳遞數(shù)據(jù):鏈接占位
- 響應(yīng)用戶操作:鏈接占位
- 內(nèi)存管理钞护、狀態(tài)標(biāo)尺:鏈接占位
- 適應(yīng)設(shè)備:鏈接占位
UIViewController示意圖
創(chuàng)建初始化界面
空界面圖示
Tips:View debug的路徑,注意:需要先運(yùn)行模擬器
View Controller Lifecycle
多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
Storyboard Reference 位置
跳轉(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;
}
}