滚动UITableView时自定义单元格重新加载问题

滚动UITableView时自定义单元格重新加载问题,uitableview,scroll,Uitableview,Scroll,我有一个UITableView,其中我使用的是自定义UITableViewCell。在UITableView被滚动之前,一切正常。当我滚动UITableView时,第二部分中的单元格开始显示第一部分中单元格的内容 我正在为我的项目使用故事板 以下是CellForRowatineXpath中的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat

我有一个UITableView,其中我使用的是自定义UITableViewCell。在UITableView被滚动之前,一切正常。当我滚动UITableView时,第二部分中的单元格开始显示第一部分中单元格的内容

我正在为我的项目使用故事板

以下是CellForRowatineXpath中的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

LS_Custom_Cell *customCell = (LS_Custom_Cell *)[tableView dequeueReusableCellWithIdentifier:@"LS_Custom_Cell" forIndexPath:indexPath];

if (indexPath.section == 0 && indexPath.row == 0) {
    customCell.selectionStyle = UITableViewCellSelectionStyleNone;
    [customCell.btnAddContact addTarget:self
                                 action:@selector(btnAddContactAction:)
                       forControlEvents:UIControlEventTouchDown];
    customCell.btnSelectContact.hidden   = YES;
    customCell.btnAddContact.hidden      = NO;
    customCell.lblAddContactText.hidden  = NO;
    customCell.lblContactName.hidden     = YES;
    customCell.lblContactEmailId.hidden  = YES;
}else if (indexPath.section == 1){
    customCell.lblContactName.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"name"]];
    customCell.lblContactEmailId.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"email"]];
}

return customCell;
}
我也附上图片,以进一步澄清这个问题

这个屏幕截图是第一次表加载记录看起来很完美

一旦我开始滚动单元格,第一部分就会出现在第二部分

这是我第一次在这里发帖,如果有任何错误,请原谅我。在这方面的任何帮助都将不胜感激。提前谢谢。

试试这个

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LS_Custom_Cell *customCell = (LS_Custom_Cell *)[tableView dequeueReusableCellWithIdentifier:@"LS_Custom_Cell" forIndexPath:indexPath];

    if (indexPath.section == 0 && indexPath.row == 0)
    {
        customCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [customCell.btnAddContact addTarget:self
                                     action:@selector(btnAddContactAction:)
                           forControlEvents:UIControlEventTouchDown];
        customCell.btnSelectContact.hidden   = YES;
        customCell.btnAddContact.hidden      = NO;
        customCell.lblAddContactText.hidden  = NO;
        customCell.lblContactName.hidden     = YES;
        customCell.lblContactEmailId.hidden  = YES;
    }

    else if (indexPath.section == 1)
    {
        customCell.btnSelectContact.hidden   = NO;
        customCell.btnAddContact.hidden      = YES;
        customCell.lblAddContactText.hidden  = YES;
        customCell.lblContactName.hidden     = NO;
        customCell.lblContactEmailId.hidden  = NO;
        customCell.lblContactName.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"name"]];
        customCell.lblContactEmailId.text = [NSString stringWithFormat:@"%@", [[contactsArray objectAtIndex:indexPath.row] valueForKey:@"email"]];
    }

    return customCell;
}