zoukankan      html  css  js  c++  java
  • 通过限时写代码,优化代码的方式。

    1.通过限时写代码,优化代码的方式。
    1.containerView -》frame:self.window.bounds

    containerView.frame = self.window.bounds 初始化窗口跟window一样大
    2.命名:View:containerView label:userNameLabel
    3.内存管理:1.View -》alloc —》对应着有一个release
    4.window的内存管理:
    1.把strong改为retain
    2.重写dealloc方法,把属性对应的实例变量给释放掉。
    3.window alloc 的时候有内存泄露。如果不明白,可以改写代码如下所示:
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;
    [window release];

    第二种方式:
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window release];//可以,但是self.window是getter方法,内部实际上还是_window,但是如果是_window的话,实例变量的释放应该放到dealloc方法里面。这种方式,不是很恰当。

    第三种:
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    [self.window addSubView:view1];===>view1 retainCount 加1 ,view1 release。。 retainCount 为1,当window release的时候,view1的引用计数为0

    On the road。。。
  • 相关阅读:
    CF1202F You Are Given Some Letters...
    CF1178E Archaeology
    PTA (Advanced Level) 1005 Spell It Right
    PTA (Advanced Level) 1004 Counting Leaves
    Qt5——从零开始的Hello World教程(Qt Creator)
    PTA (Advanced Level) 1003 Emergency
    PTA (Advanced Level) 1002 A+B for Polynomials
    HDU 1272 小希的迷宫
    FZU 2150 Fire Game
    HihoCoder
  • 原文地址:https://www.cnblogs.com/ianhao/p/4442680.html
Copyright © 2011-2022 走看看