由于四期要做多语言版本,带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.