0

我有一个 UITableView,我在其中使用自定义 UITableViewCell。一切都很好,直到 UITableView 滚动。一旦我滚动 UITableView,第二部分中的单元格就会开始显示第一部分中单元格的内容。

我正在为我的项目使用 Storyboard。

这是 cellForRowAtIndexPath 中的代码

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

我还附上了图片以进一步澄清问题。

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

http://postimg.org/image/y2114vjdl/

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

http://postimg.org/image/c5ei4i66x/

这是我第一次在这里发布问题,如果有任何错误,请原谅我。非常感谢这方面的任何帮助。提前致谢。

4

1 回答 1

0

尝试这个

- (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;
}
于 2013-05-13T04:23:57.797 回答