我有两个视图控制器,我在我的项目中使用 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;
}