zoukankan      html  css  js  c++  java
  • 做ios工程时,把UI从xib移动到代码中遇到的问题

        由于四期要做多语言版本,带xib页面的工程做多语言版本比较麻烦,再加上现在已经习惯了代码中的viewdidload函数中初始化控件,所以就把两个页面从xib移到代码中去了。

        在修改后加载页面会遇到bad access问题,后来发现还是自己粗心导致的某一个控件被多release一次。但是在调试过程中发现我的viewdidload被重复调用两次。下面附上程序代码:

            //群组成员管理
        ChatManagerViewCtrller* chatCtrller = [[ChatManagerViewCtrller alloc]init];
        [chatCtrller setGroupId:_chatUser.mName_md5];
        chatCtrller.groupInfo = _chatUser;
        [self.navigationController pushViewController:chatCtrller animated:YES];
        [chatCtrller release];
    

     setgroupid函数为:

    - (void) setGroupId:(NSString*)groupId
    {
        //groupId = @"ff80808140ee5ea20140f288c0dd0021";
        [mGroupId release];
        mGroupId = [groupId retain];
        [self getGroupInfo];
    }
    
    -(void)getGroupInfo
    {
        RequestGetGroupInfo *getGroupInfo = [[RequestGetGroupInfo alloc]init];
        getGroupInfo.receiveDelegete = self;
        getGroupInfo.groupId = mGroupId;
        
        [[NetworkModel sharedInstance]sendRequest:getGroupInfo];
        [getGroupInfo release];
        
        [DSBezelActivityView activityViewForView:self.view withLabel:@"获取群组信息中..." 120];
    }
    

     即每次都是在最后一句:

    [DSBezelActivityView activityViewForView:self.view withLabel:@"获取群组信息中..." 120];

    后调用viewdidload函数,然后程序运行至

    [self.navigationController pushViewController:chatCtrller animated:YES];

    处又会进入到viewdidload里面执行。
    后来仔细看了一下UIViewController.h中的注释发现原来是这么回事:如果我们在调用view的时候,view还没有初始化,就调用它父类的viewdidload函数,然后pushViewController函数还会再次调用该viewdidload

    @property(nonatomic,retain) UIView *view; // The getter first invokes [self loadView] if the view hasn't been set yet. Subclasses must call super if they override the setter or getter.
    
  • 相关阅读:
    week4:周测错题
    小程序1:登录/注册小程序
    小程序2:实现一个购物车
    day26:装饰器&面向对象当中的方法&property
    day25:7个魔术方法&5个关于类的魔术属性
    day24:多态&魔术方法__new__&单态模式
    day23:单继承&多继承&菱形继承&__init__魔术方法
    day22:面向对象封装对象操作&类操作&面向对象删除操作
    day21:正则函数&模块和包(import)
    APP探索之iAPP
  • 原文地址:https://www.cnblogs.com/baozou/p/3409146.html
Copyright © 2011-2022 走看看