0

我有两个视图控制器,我在我的项目中使用 sqlite。在一个控制器中,我正在创建和显示 UITableview,而在另一个控制器中,我正在通过 sqlite 删除表格单元格。我的问题是在从一个控制器执行删除操作并返回到另一个控制器时,表视图与以前的旧视图重叠。我什至删除了 tableview 并重新创建了它。问题没有解决。任何帮助表示赞赏。我附上了截图。 在此处输入图像描述

// create cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    NSString *cellIdentifier = @"Cell";

    MOProfileTablViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

    if(cell == nil)
    {
        cell = [[MOProfileTablViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

        cell.profileLabel.textColor = [UIColor whiteColor];

        [cell.profileLabel setFont: [UIFont fontWithName:kfontNameBold size:18]];

        cell.profileNumberLabel.textColor = [UIColor whiteColor];

        [cell.profileNumberLabel setFont:[UIFont fontWithName:kFontName size:14]];

    }

    if(selectedIndex == [indexPath row] && [[sqlExecutObj.result objectAtIndex:1] count] > [indexPath row])
    {
        self.preSelectedProfileViewCell = cell;

        cell.selectionButton.hidden = NO;

    }
    else
        cell.selectionButton.hidden = YES;

    if ([[sqlExecutObj.result objectAtIndex:1] count] && [[sqlExecutObj.result objectAtIndex:1] count] > [indexPath row])
    {//set cell background color
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[profileColorArray objectAtIndex:indexPath.row]]];

        cell.backgroundColor = [UIColor clearColor];
    }
    else
    {
        if ([[sqlExecutObj.result objectAtIndex:1] count]== [indexPath row]) {



        }else {
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"add_newprofile.png"]];

        cell.backgroundColor = [UIColor clearColor];
        }
    }

    if ([[sqlExecutObj.result objectAtIndex:1] count] && [[sqlExecutObj.result objectAtIndex:1] count] > [indexPath row])
    {
        cell.profileLabel.text = [[sqlExecutObj.result objectAtIndex:0] objectAtIndex:indexPath.row];

        cell.profileNumberLabel.text = [[sqlExecutObj.result objectAtIndex:3] objectAtIndex:indexPath.row]; //settings-icon.png

        if ([[[sqlExecutObj.result objectAtIndex:1] objectAtIndex:indexPath.row] isEqualToString:@"default"])
        {
            [cell.profileImage.layer setBorderWidth:0.0f];
            cell.profileImage.image = [UIImage imageNamed:@"group.png"] ;

            cell.profileImage.frame = CGRectMake(cell.selectionButton.frame.origin.x+cell.selectionButton.frame.size.width+15,13,30 ,30);
        }
        else
        {
            [cell.profileImage.layer setBorderWidth:2.0f];

            cell.profileImage.frame = CGRectMake(cell.selectionButton.frame.origin.x+cell.selectionButton.frame.size.width+15,10,30 , 30);

            UIImage *imge=[UIImage imageWithData:[NSData dataWithContentsOfFile:[[sqlExecutObj.result objectAtIndex:1]objectAtIndex:indexPath.row]]];

            cell.profileImage.image = imge;
        }
        if ( [ [ [sqlExecutObj.result objectAtIndex:0] objectAtIndex:indexPath.row] isEqualToString:@"PENDING..."] || [ [ [sqlExecutObj.result objectAtIndex:0] objectAtIndex:indexPath.row] isEqualToString:@"New Virtual Number"] ) {

            cell.accessoryType =UITableViewCellAccessoryNone;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
             [cell.profileLabel setFont:[UIFont fontWithName:kFontName size:16.5]];

        } else {
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        }
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
         if ([[sqlExecutObj.result objectAtIndex:1] count] == [indexPath row]) {
             //customizing cell for manage account
        cell.profileLabel.text = @"Manage Account";
        cell.profileLabel.frame = CGRectMake(cell.profileImage.frame.origin.x+cell.profileImage.frame.size.width+10,12,150,24);
        cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"settings-bg.png"]];   //settings-icon.png
        cell.profileNumberLabel.text = nil;
        [cell.profileImage.layer setBorderWidth:0.0f];
        cell.profileImage.image = [UIImage imageNamed:@"settings-icon.png"] ;
        cell.profileImage.frame = CGRectMake(cell.selectionButton.frame.origin.x+cell.selectionButton.frame.size.width+15,10,30 ,30);
        [cell.profileLabel setFont:[UIFont fontWithName:kFontName size:18]];
        cell.profileLabel.textColor = [UIColor whiteColor];
         }
         else
         {
             //customizing cell for add-new-profile cell
        cell.profileLabel.text = nil;
        cell.profileNumberLabel.text = nil;
        cell.profileImage.image = nil;
        [cell.profileLabel setFont:[UIFont fontWithName:kFontName size:20]];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;


         }
    }

    return cell;

}
4

1 回答 1

1

看起来您没有cellIdentifier正确使用标识符:当您定义单元格时,您在构造函数中传递了标识符,但是当您尝试使单元格出列时,您传递了nil

MOProfileTablViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
//                                                                        ^^^^
//                                                                        HERE

文档特别要求该参数不是nil

identifier

  • 标识要重用的单元对象的字符串。此参数不得为nil

通常,您的方法看起来“很忙”:如果您需要在不同情况下以不同方式配置单元格,请考虑对具有不同外观的单元格使用不同的重用标识符。这将有助于防止此类情况发生,也有助于您在滚动表格时提高帧速率。

于 2013-09-26T16:09:14.370 回答