之前的 代码 每次调用点击函数 都会重新再去创建一次 导致内存 泄露 最终程序崩溃
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row==1) {
view01=[[UIView alloc] initWithFrame:CGRectMake(50, ScreenHeight-350, ScreenWidth-100, 150)];
view01.backgroundColor=[UIColor lightGrayColor];
//请输入队员人数
UILabel * lab=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-100, 40)];
lab.text=@"请输入队员人数";
lab.backgroundColor=clear;
lab.font=[UIFont boldSystemFontOfSize:15.0f];
lab.textAlignment=NSTextAlignmentCenter;
lab.userInteractionEnabled=YES;
[view01 addSubview:lab];
[lab release];
//创建输入框
receive=[[UITextField alloc] initWithFrame:CGRectMake(35, 45, 160, 40)];
receive.borderStyle=UITextBorderStyleRoundedRect;
receive.autoresizingMask = UIViewAutoresizingFlexibleWidth;
receive.textColor = [UIColor blackColor];
receive.keyboardType= UIKeyboardTypeNumberPad;
receive.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
receive.autocapitalizationType = UITextAutocapitalizationTypeNone;
receive.font=[UIFont systemFontOfSize:15];
receive.delegate=self;
[view01 addSubview:receive];
[receive release];
btn=[[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[btn setTitle:@"确定" forState:UIControlStateNormal];
[btn setFrame:CGRectMake(60, 95, 100, 40)];
[btn addTarget:self action:@selector(returnClick) forControlEvents:UIControlEventTouchUpInside];
[view01 addSubview:btn];
[self.view bringSubviewToFront:view01];
[self.view addSubview:view01];
[view01 release] ;
}
}
秦歌交了 改过之后的代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row==1) {
if (!view01) {//这里做出一个判断 没有就创建 存在就不创建
view01=[[UIView alloc] initWithFrame:CGRectMake(50, ScreenHeight-350, ScreenWidth-100, 150)];
view01.backgroundColor=[UIColor lightGrayColor];
//其他三个元素 放在上面就好了 也只是 随着 view01 只创建一次
btn=[UIButton buttonWithType:UIButtonTypeRoundedRect] ;
[btn setTitle:@"确定" forState:UIControlStateNormal];
[btn setFrame:CGRectMake(60, 95, 100, 40)];
[btn addTarget:self action:@selector(returnClick) forControlEvents:UIControlEventTouchUpInside];
[view01 addSubview:btn];
//请输入队员人数
UILabel *lab=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-100, 40)];
lab.text=@"请输入队员人数";
lab.backgroundColor=clear;
lab.font=[UIFont boldSystemFontOfSize:15.0f];
lab.textAlignment=NSTextAlignmentCenter;
lab.userInteractionEnabled=YES;
[view01 addSubview:lab];
[lab release];
//创建输入框
receive=[[UITextField alloc] initWithFrame:CGRectMake(35, 45, 160, 40)];
receive.borderStyle=UITextBorderStyleRoundedRect;
receive.autoresizingMask = UIViewAutoresizingFlexibleWidth;
receive.textColor = [UIColor blackColor];
receive.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
receive.keyboardType= UIKeyboardTypeNumberPad;
receive.autocapitalizationType = UITextAutocapitalizationTypeNone;
receive.font=[UIFont systemFontOfSize:15];
receive.delegate=self;
[view01 addSubview:receive];
[receive release];
}
最终创建好试图 后 再做处理
[self.view bringSubviewToFront:view01];
[self.view addSubview:view01];
//[view01 release] ; //这里的view是不可以释放的 以防止用户不小心 重复的点击cell 点一次 release一次 这样就直接崩溃了 上午调了半天。。。。。
}
}