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.
    
  • 相关阅读:
    python实战===教你用微信每天给女朋友说晚安
    [go]beego获取参数/返回参数
    [go]os.Open方法源码
    [go]从os.Stdin探究文件类源码
    [svc]linux中的文件描述符(file descriptor)和文件
    [net]tcp和udp&socket
    [django]update_or_create使用场景
    [sh]shell语法小结
    [drf]访问文档出现错误'AutoSchema' object has no attribute 'get_link'
    [py]python操作zookeeper
  • 原文地址:https://www.cnblogs.com/baozou/p/3409146.html
Copyright © 2011-2022 走看看