zoukankan      html  css  js  c++  java
  • UIController中view的记载流程

    //初始化方法

    - (id)init{

        

        if (self = [super init]) {

            NSLog(@"%@",self.view);

        }

        return self;

     }

    //view的get方法

    - (UIView *)view{

    //如果View存在,就返回

        if ([self valueForKey:@"_view"]) {

            return [self valueForKey:@"_view"];

        }

        //如果不存在,先调用loadView 再调用ViewDidLoad

        [self loadView];

        [self viewDidLoad];

         return [self valueForKey:@"_view"];

     }

     - (void)loadView{

           //判断读取xib文件的路径是否存在

        NSFileManager *manager = [NSFileManager defaultManager];

          NSString *path = [[[NSBundle mainBundle]bundlePath]stringByAppendingFormat:@"/%@.nib",NSStringFromClass([self class])];

         if ([manager fileExistsAtPath:path]) {

            //通过xib文件加载视图

            //LoadNib....可以返回一个含有xib文件中的视图元素数组(View View1)

            //owner 参数必须要写,如果不写,不会对声明了IBOutle的变量赋值

            [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];

            return;

        }

     //如果不存在xib文件,则初始化一个白得视图

        UIView *view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];

        view.backgroundColor = [UIColor redColor];

        //给self.view赋值

        [self setView:view];

      }

    - (void)viewDidLoad{

     [super viewDidLoad];

         //在viewDidLoad方法中,不能使用superView,因为view的get方法还没有做完,肯定没有添加到其他视图

         NSLog(@"%@",self.view.subviews);

         //在init方法中不能出现

        NSLog(@"%@",self.title);

        

         //请解释死循环

    //    self.view = nil;

    //    NSLog(@"%@",self.view);

    }

  • 相关阅读:
    HDU 6071
    HDU 6073
    HDU 2124 Repair the Wall(贪心)
    HDU 2037 今年暑假不AC(贪心)
    HDU 1257 最少拦截系统(贪心)
    HDU 1789 Doing Homework again(贪心)
    HDU 1009 FatMouse' Trade(贪心)
    HDU 2216 Game III(BFS)
    HDU 1509 Windows Message Queue(队列)
    HDU 1081 To The Max(动态规划)
  • 原文地址:https://www.cnblogs.com/wen-1992/p/4760565.html
Copyright © 2011-2022 走看看