Objective c 滚动时覆盖UITableView中的单元格

Objective c 滚动时覆盖UITableView中的单元格,objective-c,ios7,xcode6,Objective C,Ios7,Xcode6,我知道这是一个重复的问题,但我没有得到我的问题的解决方案。我以编程方式设计了UITableView,但它在4节或9行之前工作正常,但当我尝试添加任何额外单元格时,它会覆盖最后一个单元格上的第一个单元格,反之亦然。请解决我的问题。提前感谢。 我的代码是- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 6; } -(NSInteger)tableView:(UITableView *)ta

我知道这是一个重复的问题,但我没有得到我的问题的解决方案。我以编程方式设计了UITableView,但它在4节或9行之前工作正常,但当我尝试添加任何额外单元格时,它会覆盖最后一个单元格上的第一个单元格,反之亦然。请解决我的问题。提前感谢。

我的代码是-

-(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;
}

else if(section==5)返回1;否则返回0我想你这里有个问题。。。请尝试返回3。很抱歉..我输入了3,但由于错误,我在这里输入了1..它仍然被覆盖我解决了问题…只需更改一行UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:nil];而不是UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];杰出的我的问题也解决了。。谢谢你的提问