今天写了个demo才发现,当尝试在函数: func application(_ application: UIApplication, didFinishLaunchingWithOptions la
做一个实验,通过实验来分析viewController的生命周期。 和生命周期几个相关的方法 - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"FirstVC viewDidLoad"); } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear]; NSLog(@"FirstVC viewWillAppear"); } - (void)didRe
dict = [array objectAtIndex:indexPath.row]; NSString * str = [dict objectForKey:@"viewController"]; UIViewController
一、视图控制器 UIViewController采用懒加载的方式,也就是说第一次访问到view属性时才会加载或创建它。 这需要我们在loadView 方法中,通过编程创建自己的视图层次,并且把把根视图赋值给UIViewController的view属性。 1、loadView loadView方法是用来负责创建UIViewController的view 首先,[super loadView]会先去查找与UIViewController相关联的xib文件, 通过加载xib文件来创建UIViewController的view 如果没有找到相关联的xib文件,就会创建一个空白的UIView,然后赋值给UIViewController的view属性 默认不用实现 每次访问UIViewController的view(比如controller.view、self.view)而且view为nil,loadView方法就会被调用。
1 UIViewController机制 1.1 生命周期 UIViewController生命周期 理解view的生命周期: 在UIViewController 出现unbalanced calls to begin/end appearance transitions for uiviewcontroller这样的log,其原因就是在容器类的UIViewController :(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration :(UIViewController )presentingsourceController:(UIViewController *)source; -(id)animationControllerForDismissedController *)presented presentingController:(UIViewController *)presenting sourceController: (UIViewController
案例 import UIKit class ViewController: UIViewController { // UIContentUnavailableConfiguration
UIViewController有2周期: 在UIViewController中,View存在两个循环:载入循环和卸载循环。 载入循环 1》程序请求controller的view。 则UIViewController调用loadView方法。 假设你没有重载这个函数,UIViewController会默认使用UIViewController的nibName和nibBundle属性尝试从nib文件载入view。 2》每一个UIViewController调用didReceiveMemoryWarning。默认会安全地释放掉view。 UIViewController的生命周期: 当一个视图控制器被创建。并在屏幕上显示的时候。
跳转 从一个 UIViewController 跳转到另一个 UIViewController 有两种方式,分别为模态跳转和导航跳转。 通过当前 UIViewController 某个具体的控件(如按钮)拽线到另一个 UIViewController。 手动型 Segue 从当前 UIViewController 拽线到另一个 UIViewController,需要给这根线设置identifier。 可以展示多个 UIViewController,这些 UIViewController 是层级关系。 可以展示多个 UIViewController,这些 UIViewController 是平级关系。但展示的 UIViewController 最多不超过5个,否则会折叠。
class subViewController: UIViewController { //nib文件的初始化 override init(nibName nibNameOrNil
原因:当我们使用NSTimer的方法时,定时器对象会对它的target(即self:当前控制器)持有强引用,如果定时器不销毁,则控制器无法释放。
- (UIViewController *)getCurrentVC { UIViewController *result = nil; UIWindow * window = [[UIApplication objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController } else { result = window.rootViewController; } return result; } 第二种写法: //登录接口 UIViewController objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController
介绍 WWDC24 中 UIViewController 增加了 5 种特殊的转场效果zoom、coverVertical、flipHorizontal、crossDissolve与partialCurl import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad context.zoomedViewController is NextViewController else { fatalError("Unable to access the current UIViewController self.navigationItem.rightBarButtonItem } present(nextViewController, animated: true) } } class NextViewController: UIViewController
介绍增加了类型为UIViewController.Transition的preferredTransition属性,可以实现特殊的转场效果,共有 5 种效果,分别为zoom、coverVertical、 使用zoom效果import UIKitclass ViewController: UIViewController { lazy var button: UIButton = { { dismiss(animated: true) }}coverVertical效果import UIKitclass ViewController: UIViewController { dismiss(animated: true) }}flipHorizontal效果import UIKitclass ViewController: UIViewController { dismiss(animated: true) }}partialCurl效果import UIKitclass ViewController: UIViewController
简述 本文将讲述在iOS开发中如何根据某个UIView来获取所属的UIViewController UIResponder 在iOS中UIResponder类是专门用来响应用户的操作处理各种事件的,包括触摸事件 我们知道UIApplication、UIView、UIViewController这几个类是直接继承自UIResponder,所以这些类都可以响应事件。 当然我们自定义的继承自UIView的View以及自定义的继承自UIViewController的控制器都可以响应事件。 20170512174229676.png 代码 - (UIViewController *)getControllerFromView:(UIView *)view { // 遍历响应者链。 class]]){ return (UIViewController *)responder; } } // 如果没有找到则返回nil
介绍 增加了类型为UIViewController.Transition的preferredTransition属性,可以实现特殊的转场效果,共有 5 种效果,分别为zoom、coverVertical 使用 zoom效果 import UIKit class ViewController: UIViewController { lazy var button: UIButton = { { dismiss(animated: true) } } zoom coverVertical效果 import UIKit class ViewController: UIViewController coverVertical present(nextViewController, animated: true) } } class NextViewController: UIViewController .partialCurl present(nextViewController, animated: true) } } class NextViewController: UIViewController
NewViewController viewDidLoad] + 85 9 UIKitCore 0x00007fff46af87c2 -[UIViewController loadViewIfRequired] + 1084 11 UIKitCore 0x00007fff46afdaf0 -[UIViewController animated:completion:]_block_invoke + 98 16 UIKitCore 0x00007fff46b11d23 -[UIViewController ViewController viewDidAppear:] + 146 20 UIKitCore 0x00007fff46b036a2 -[UIViewController setViewAppearState:isAnimating:] + 934 23 UIKitCore 0x00007fff46b040a6 -[UIViewController
UIViewController的生命周期及iOS程序执行顺序 当一个视图控制器被创建,并在屏幕上显示的时候。 当我们创建一个UIViewController类的对象时,通常系统会生成几个默认的方法,这些方法大多与视图的调用有关,但是在视图调用时,这些方法的调用顺序如何,需要整理下。 通常上述方法包括如下几种,这些方法都是UIViewController类的方法: - (void)viewDidLoad; - (void)viewDidUnload; - (void)viewWillAppear
iOS中的UIViewController是UIKit框架中最基本的一个类。从第一个UI视图到复杂完整项目,都离不开UIViewController作为基础。 基于UIViewController的封装和扩展,也能够出色的完成各种复杂界面逻辑。 这篇博客,旨在讨论UIViewController的生命周期和属性方法,在最基础的东西上,往往会得到意想不到的惊喜。 二、UIViewController的生命周期 要了解UIViewController,先要弄清楚其生命周期。 在面向对象的语言中,是对象,就一定要有生命周期,UIViewController也不例外,生命周期管理Controller的作用范围和时间,也管理其内对象的作用范围和时间。
在平时的开发中会遇到下面两种场景: 有些特殊页面需要判断是通过push/pop 或 模态化的方式进入/退出; 页面出现/消失的时机; UIViewController出现 override func } else { print("页面通过导航栏pop退回该页面 / 页面通过模态化dismiss退回该页面") } } UIViewController
iOS开发中,创建View常见的两种方式一个是纯代码,一个是借助于XIB;创建ViewController常见的也有两种方式一个是纯代码,一个是借助于StoryBoard。 通过交流我发现很多童鞋对这些概念都很模糊,于是通过实验写一篇博客供参考。 重写View的如下方法 @implementation YFView -(instancetype)init{ self = [super init]; NSLog(@"%s", __func__); re