我知道这是一个重复的问题,但我没有在我的问题上得到解决方案..我已经以编程方式设计了UITableView但是它工作正常直到4节或9行但是当我试图添加任何额外的单元格时它& #39;覆盖最后一个细胞的第一个细胞,反之亦然。请解决我的问题。谢谢。
我的代码是 -
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return 1;
else if (section == 1)
return 1;
else if (section == 2)
return 3;
else if (section == 3)
return 2;
else if (section == 4)
return 2;
else if (section == 5)
return 3;
else
return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
if ((indexPath.section == 0) && (indexPath.row ==0)) {
cell.textLabel.text = @"";
//Get it from previous view
chooseEventLbl.text = @"Choose an event";
//chooseEventLbl.textColor = [UIColor darkGrayColor];
[cell addSubview:chooseEventLbl];
//cell.textLabel.text = @"Choose an event";
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
[image setImage:[UIImage imageNamed:@"arrow_list.png"]];
cell.accessoryView = [[UIImageView alloc]initWithFrame:CGRectMake(260.0, 7.0, 10, 20)];
[cell.accessoryView addSubview:image];
}
else if ((indexPath.section == 1) && (indexPath.row == 0))
{
cell.textLabel.text = @"";
[cell addSubview:squareNameTxt];
}
else if ((indexPath.section == 2) && (indexPath.row == 0))
{
cell.textLabel.text = @"Public";
}
else if ((indexPath.section == 2) && (indexPath.row == 1))
{
cell.textLabel.text = @"Private";
}
else if ((indexPath.row == 2) && (indexPath.row == 2) && (passwordFlag == TRUE))
{
cell.textLabel.text = @"";
[cell addSubview:passwordTxt];
// passwordTxt.enabled = NO;
}
else if ((indexPath.section == 3) && (indexPath.row == 0))
{
cell.textLabel.text = @"Allow multiple Squares";
[aSwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
aSwitch.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:aSwitch];
}
else if ((indexPath.section == 3) && (indexPath.row == 1)) {
cell.textLabel.text = @"";
[cell addSubview:multiSquareListBtn];
}
else if ((indexPath.section == 4) && (indexPath.row == 0))
{
cell.textLabel.text = @"Prizes";
}
else if ((indexPath.section == 4) && (indexPath.row == 1))
{
cell.textLabel.text = @"";
[cell addSubview: firstQuarterTxt];
[cell addSubview:halftimeTxt];
[cell addSubview:thirdQuarterTxt];
[cell addSubview:finalTxt];
}
else if ((indexPath.section == 5) && (indexPath.row ==0))
{
cell.textLabel.text= @"";
currentLocationLbl.text = @"Choose Current Location";
[cell addSubview:currentLocationLbl];
}
else if ((indexPath.section == 5) && (indexPath.row == 1))
{
cell.textLabel.text = @"";
mapLocationLbl.text = @"Choose location from Map";
[cell addSubview:mapLocationLbl];
}
else if ((indexPath.section == 5) && (indexPath.row == 2))
{
cell.textLabel.text = @"";
radiusLocationLbl.text = @"Location Radius";
[cell addSubview:radiusLocationLbl];
}
return cell;
}