iphone - ios 中的 UITableView 问题 - 甚至从 super View 中删除了以前 View 的重叠

标签 iphone ios

我有两个 View Controller ,我在我的项目中使用 sqlite。在一个 Controller 中,我正在创建并显示 UITableview,而在另一个 Controller 中,我正在通过 sqlite 删除表格单元格。我的问题是在从一个 Controller 执行删除操作并返回到另一个 Controller 时, TableView 与以前的旧 View 重叠。我什至删除了 tableview 并重新创建了它。问题没有解决。任何帮助表示赞赏。 我附上截图。 enter image description here

// 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;

}

最佳答案

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

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

文档特别要求该参数不能为 nil:

identifier

  • A string identifying the cell object to be reused. This parameter must not be nil.

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

关于iphone - ios 中的 UITableView 问题 - 甚至从 super View 中删除了以前 View 的重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19032572/

相关文章:

ios - OneSignal + React Native + 后台通知

iphone - 在 iOS 中取消存档 NSAttributedString

ios - 呈现具有从左到右过渡的透明背景的新 View Controller 时出现问题

iphone - 如何在 UIButton 上动态设置不同的字体?

iphone - ios 如何在添加或删除文本时自动调整 uilabel 的高度(和 numberOfLines = 0)

ios - 为什么我的委托(delegate)为空?

ios - 如何从另一个类访问 IBOutlet

iphone - 当出现内存不足警告时,核心数据是否会自动采取适当的措施?

ios - UICollectionViewUpdateItem 可以用来更新单个标签吗?

iphone - 使用 AVCaptureSession 录制视频