Iphone 无法在tableviewcell ios 7上显示删除按钮

Iphone 无法在tableviewcell ios 7上显示删除按钮,iphone,ios,objective-c,ios7,Iphone,Ios,Objective C,Ios7,我使用UITableviewcellEditingstyleDelete为用户显示按钮单击它显示删除按钮(这与您在电子邮件应用程序上看到的方式相同,用户单击编辑,然后单击按钮显示删除按钮)。在ios6中工作正常,但当我在有ios 7的设备上构建应用程序时,删除按钮消失,但当你点击删除按钮的区域时,它也可以删除。问题是用户看不到删除按钮(操作系统提供的红色按钮)。 我的代码是: - (UITableViewCellEditingStyle)tableView:(UITableView *)aTab

我使用
UITableviewcellEditingstyleDelete
为用户显示按钮单击它显示删除按钮(这与您在电子邮件应用程序上看到的方式相同,用户单击编辑,然后单击按钮显示删除按钮)。在ios6中工作正常,但当我在有ios 7的设备上构建应用程序时,删除按钮消失,但当你点击删除按钮的区域时,它也可以删除。问题是用户看不到删除按钮(操作系统提供的红色按钮)。 我的代码是:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Detemine if it's in editing mode
    if (self.editing)
    {
       return UITableViewCellEditingStyleDelete;
    }

   return UITableViewCellEditingStyleNone;
}

请帮我找到解决方案,我对iOS7环境了解不多。谢谢

您不需要检查是否正在编辑tableView…只需实现:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
       return UITableViewCellEditingStyleDelete;
}

它看起来像是iOS 7中的一个Bug。由于某种原因,
backgroundView
会通过删除按钮移动
iOS
。您可以通过对
backgroundView
进行子分类并实现派生视图的
setFrame
功能来解决此问题,如下所示:


当指定了
accesoryView
并且
editingAccessoryView
nil
时,也可能发生这种情况。此处对该问题和解决方案进行了详细说明:


消除此问题的最佳方法是在单元格中添加图像并将其设置在背面

      UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImg.png"]];
      imageView.frame = CGRectMake(0, 0, 320, yourCustomCell.frame.size.height);
      [yourCustomCell addSubview:imageView];
      [yourCustomCell sendSubviewToBack:imageView];
如果文本与删除按钮重叠,则实现自动布局。它将以更好的方式管理它

还可以生成另一种情况,即cellSelectionStyle将使用默认颜色高亮显示。可以按如下方式设置高光颜色

      yourCustomCell.selectionStyle = UITableViewCellSelectionStyleNone;

 Set your table cell's selection style to UITableViewCellSelectionStyleNone. This will remove the blue background highlighting or other. Then, to make the text label or contentview highlighting work the way you want, use this method in yourCustomCell.m class.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    if (highlighted)
        self.contentView.backgroundColor = [UIColor greenColor];
     else
        self.contentView.backgroundColor = [UIColor clearColor];
}
我希望它能帮助您理解。

更简单的解决方法 假设一个只有iOS7的应用程序,其技术与上面文中所链接的类似,我相信这里的方法是:更干净

在这种方法中,您不需要对backgroundView进行子类化,因为对于不同的单元格,backgroundView可能会有所不同

将代码放在我上面链接到的答案中,放在自定义表格单元格层次结构的根目录中,以及所有表格单元格(从中继承的),无论何时使用backgroundView或selectedBackgroundView属性,都可以得到修复


复制此要点中的解决方案:

谢谢大家的建议,此解决方案可以解决此问题,我将其放入自定义单元格中

 UIImageView* backgroundImage;

//Variable for animation delete button
// Keep the ContactView in normal state
BOOL bFirstEditingCell;
BOOL bShownRedMinus;
BOOL bShownDeleteButton;
CGRect frameOfContactViewInNormal;
CGPoint centerOfCellInNormal;
UITableViewCellAccessoryType accessoryTypeInNormal;
//


解决此问题的一个简单方法是将
删除确认按钮视图
设置为前视图。可以通过在
customtableviewcell.m
文件中实现委托方法
layoutSubviews
来完成

在我的例子中,我通过将以下代码添加到
customtableviewcell.m
文件中解决了这个问题。根据视图在单元格中的放置方式,可能会略有不同。但它肯定会让你知道如何解决这个问题

- (void)layoutSubviews // called when a interface orientation occur ie. in our case when the '-' button clicks
{
[super layoutSubviews];

for (UIView *subview in self.subviews) { // Loop through all the main views of cell

   // Check the view is DeleteConfirmationView or not, if yes bring it into the front 
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) { 

            [self bringSubviewToFront:subview];// code for bring the view into the front of all subviews

        }

    }
}

问题是我的backgroundview的图像与删除按钮重叠,我还想为背景视图设置图像。我已经仔细阅读了你的建议,但我没有任何想法。我如何对我的backgroundview进行分类?这似乎是IOS 7的一个缺陷,所以我尝试了你的代码,但没有影响。我想,文的答案是对的,但我不知道如何处理他的想法。可能是重复的
- (void)layoutSubviews // called when a interface orientation occur ie. in our case when the '-' button clicks
{
[super layoutSubviews];

for (UIView *subview in self.subviews) { // Loop through all the main views of cell

   // Check the view is DeleteConfirmationView or not, if yes bring it into the front 
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) { 

            [self bringSubviewToFront:subview];// code for bring the view into the front of all subviews

        }

    }
}