我正在为 iphone 应用程序做一份注册表。在那有一个带有四个部分的表格视图。在最后一部分中,有一行带有注册按钮。我得到了带有数据的表格视图。但是在向上和向下滚动表格视图时,我的注册按钮转到第二部分。我添加了下面的代码.我在这做错了什么。帮我解决。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
// static NSString *CellIdentifier = @"Cell";
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *identifier = @"reuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
NSLog(@" row and section ===== %d,%d",indexPath.row,indexPath.section);
if(indexPath.section != 3)
{
UILabel *lbl_title = [[UILabel alloc] initWithFrame:(isiPad?CGRectMake(7,10,250,50):CGRectMake(70,40,340, 35))];
[lbl_title setFont:[UIFont fontWithName:@"Verdana-Bold" size:(isiPad?20:13)]];
lbl_title.backgroundColor = [UIColor clearColor];
[lbl_title setTextColor:[UIColor blackColor]];
lbl_title.tag = ((indexPath.section+1)*10)+indexPath.row;
//NSLog(@"lbl data tag %d",lbl_title.tag);
lbl_title.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:lbl_title];
UILabel *lbl_data = [[UILabel alloc] initWithFrame:(isiPad?CGRectMake(260,10,410,50):CGRectMake(70,40,340, 35))];
[lbl_data setFont:[UIFont fontWithName:@"Verdana-Bold" size:(isiPad?20:13)]];
lbl_data.backgroundColor = [UIColor clearColor];//25-25-112
[lbl_data setTextColor:[UIColor colorWithRed:25.0/255.0 green:25.0/255.0 blue:112.0/255.0 alpha:1.0]];
lbl_data.textAlignment = UITextAlignmentCenter;
lbl_data.tag = ((indexPath.section+1)*100)+indexPath.row;
//NSLog(@"lbl data tag %d,%@",lbl_data.tag,lbl_data);
[cell.contentView addSubview:lbl_data];
if(indexPath.section == 0)
{
if(indexPath.row == 0)
{
lbl_title.text = @"Email";
}
else if(indexPath.row == 1)
{
lbl_title.text = @"Password";
}
else if(indexPath.row == 2)
{
lbl_title.text = @"Confirm password";
}
}
else if(indexPath.section == 1)
{
if(indexPath.row == 0)
{
lbl_title.text = @"First name";
}
else if(indexPath.row == 1)
{
lbl_title.text = @"Last name";
}
else if(indexPath.row == 2)
{
lbl_title.text = @"Nickname";
}
else if(indexPath.row == 3)
{
lbl_title.text = @"Gender";
}
}
else if(indexPath.section == 2)
{
if(indexPath.row == 0)
{
lbl_title.text = @"City";
}
else if(indexPath.row == 1)
{
lbl_title.text = @"State";
}
else if(indexPath.row == 2)
{
lbl_title.text = @"Country";
}
}
}
if(indexPath.section == 3)
{
if(indexPath.row == 0)
{
cell.backgroundColor = [UIColor colorWithRed:165.0/255.0 green:42.0/255.0 blue:42.0/255.0 alpha:1.0];//165-42-42
UIButton *btn_register = [[UIButton alloc] initWithFrame:isiPad?CGRectMake(10,0,660,70):CGRectMake(0,0,320,40)];
[btn_register addTarget:self action:@selector(btn_register_clicked:) forControlEvents:UIControlEventTouchUpInside];
[btn_register setTitle:@"Register" forState:UIControlStateNormal];
//btn_register.titleLabel.textAlignment = UITextAlignmentCenter;
btn_register.backgroundColor = [UIColor blueColor];
[btn_register setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btn_register setFont:[UIFont fontWithName:@"Verdana-Bold" size:24]];
[cell.contentView addSubview:btn_register];
}
}
}
else
{
NSLog(@"updating cell.........");
}
return cell;
}