这3节课互相关联性较强,因此把笔记放一起了。
有关调试的内容放在其它笔记里
MVC(Model-View-Controller)
是一种应用程序设计框架
MVC.jpg App Overview.png补充阅读:
https://en.wikipedia.org/wiki/Model–view–controller
主流设计模式简介
主流设计模式.jpgUIViewController
作用:
管理View的Controller
具体作用:
- 管理View:链接占位
- 传递数据:链接占位
- 响应用户操作:链接占位
- 内存管理、状态标尺:链接占位
- 适应设备:链接占位
UIViewController示意图
UIViewController.jpg创建初始化界面
创建初始化界面.jpg空界面图示
空界面图示.jpgTips:View debug的路径,注意:需要先运行模拟器
Capture View Hierarchy.pngView Controller Lifecycle
UIViewController Class Reference_2x.png多View Controller常用方法和属性
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion;
//View风格
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle;
//风格枚举
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet,
UIModalPresentationFormSheet ,
UIModalPresentationCurrentContext ,
UIModalPresentationCustom ,
UIModalPresentationOverFullScreen ,
UIModalPresentationOverCurrentContext ,
UIModalPresentationPopover ,
UIModalPresentationNone = -1,
};
//动画风格
@property(nonatomic,assign) UIModalTransitionStyle modalTransitionStyle;
//风格枚举
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 ;//全部撤销,数据会丢失
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.jpgStoryboard Reference 位置
Storyboard Refa.png跳转和传值
//跳转
[self showViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"vc2"] sender:sender];
//用代码执行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;
}
}
网友评论