一、简述
UIViewController管理视图的控制器,在MVC设计模式下,Controller起链接作用,将model数据通过UIView展现给用户。
二、属性
@property(null_resettable, nonatomic,strong) UIView *view;
@property(nullable, nonatomic,copy) NSString *title;
//父视图控制器
@property(nullable,nonatomic,weak,readonly) UIViewController *parentViewController;
三、方法
//构造方法,在XIB中使用
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
//实例
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
NSLog(@"初始化-------%@",NSStringFromSelector(_cmd));
}
return self;
}
- (id)init {
self = [super init];
if (self) {
[self setup];
NSLog(@"初始化-------%@",NSStringFromSelector(_cmd));
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
NSLog(@"初始化-------%@",NSStringFromSelector(_cmd));
}
return self;
}
//如果子类使用XIB,使用它用来呼叫视图
- (void)loadView;
//如果未设置视图,用来加载视图控制器的视图
- (void)loadViewIfNeeded NS_AVAILABLE_IOS(9_0);
//在将要释放视图控制器的视图时调用
- (void)viewWillUnload NS_DEPRECATED_IOS(5_0,6_0) __TVOS_PROHIBITED;
//在释放视图控制器的视图并将其设置为nil后调用。
- (void)viewDidUnload NS_DEPRECATED_IOS(3_0,6_0) __TVOS_PROHIBITED;
//在加载视图后调用
- (void)viewDidLoad;
//加载视图的名字
@property(nullable, nonatomic, readonly, copy) NSString *nibName;
//加载的哪一个nib包
@property(nullable, nonatomic, readonly, strong) NSBundle *nibBundle;
@property(nullable, nonatomic, readonly, strong) UIStoryboard *storyboard NS_AVAILABLE_IOS(5_0);
//使用XIB时用到,自己习惯使用纯代码编写项目,再此未做过多了解
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender NS_AVAILABLE_IOS(5_0);
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender NS_AVAILABLE_IOS(6_0);
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender NS_AVAILABLE_IOS(5_0);
- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender NS_AVAILABLE_IOS(6_0);
- (NSArray *)allowedChildViewControllersForUnwindingFromSource:(UIStoryboardUnwindSegueSource *)source NS_AVAILABLE_IOS(9_0);
- (nullable UIViewController *)childViewControllerContainingSegueSource:(UIStoryboardUnwindSegueSource *)source NS_AVAILABLE_IOS(9_0);
- (nullable UIViewController *)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(nullable id)sender NS_DEPRECATED_IOS(6_0, 9_0);
- (void)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC NS_AVAILABLE_IOS(9_0);
- (nullable UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(nullable NSString *)identifier NS_DEPRECATED_IOS(6_0, 9_0);
//视图将要出现时调用
- (void)viewWillAppear:(BOOL)animated;
//视图出现时调用
- (void)viewDidAppear:(BOOL)animated;
//视图将哟啊消失时调用
- (void)viewWillDisappear:(BOOL)animated;
//使用消失后调用
- (void)viewDidDisappear:(BOOL)animated;
//在调用视图控制器的视图的layoutSubviews方法之前调用。子类可以根据需要实现。
- (void)viewWillLayoutSubviews NS_AVAILABLE_IOS(5_0);
//在调用视图控制器的视图的layoutSubviews方法之后调用。子类可以根据需要实现。
- (void)viewDidLayoutSubviews NS_AVAILABLE_IOS(5_0);
//当应用程序收到内存警告时调用
- (void)didReceiveMemoryWarning;
//不带导航栏的视图控制器之间的切换
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);