UITableViewCell删除按钮被掩盖了 [英] UITableViewCell delete button gets covered up

查看:121
本文介绍了UITableViewCell删除按钮被掩盖了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:



感谢Evgeny S提供的信息,我已经确定覆盖删除按钮的是细胞背景。我在单元格init的开头调用了以下函数:

   - (void)setupGradientsWithHeight:(int)the_height 
{
CAGradientLayer * gradient = [CAGradientLayer layer];

gradient.frame = CGRectMake(self.bounds.origin.x,
self.bounds.origin.y,
self.bounds.size.width,
高度);

gradient.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithRed:218.0f / 255.0f
green:218.0f / 255.0f
blue:220.0 f / 255.0f
alpha:1.0] .CGColor,
(id)[UIColor colorWithRed:180.0f / 255.0f
green:180.0f / 255.0f
blue:184.0f /255.0f
alpha:1.0] .CGColor,nil];

UIView * bgview = [[UIView alloc] initWithFrame:CGRectMake(0,0,1,1)];

[bgview.layer addSublayer:gradient];
[self setBackgroundView:bgview];
}

问题通过不添加backgroundview来解决。但是,我想知道如何在保留每个单元格的渐变背景的同时解决它?



可能会发生两件事之一。当删除按钮出现时,背景视图要么被移动然后又被移回 - 或者它的大小正在减小然后再返回。
我尝试使用渐变框架的宽度组件self.bounds.size.width,但我仍然没有看到它会如何影响事物,因为此函数仅在单元初始化时调用一次。



原始帖子:



我在iOS6 SDK下的Xcode4中创建了一个应用程序 - 但是在新版本中加载后环境(Xcode5和iOS7 SDK)我遇到了一个问题。请注意,我已经解决了转换时出现的所有构建错误和警告。



我有一些包含一些单元格的表格视图。进入编辑模式后,如果单击红色切换按钮以启动单元格的删除模式 - 动画开始并显示删除按钮 - 但只是短暂,然后突然重新隐藏。



我应该注意的另一个奇怪的事情是,即使删除按钮被覆盖 - 你仍然可以点击它应该的位置并删除单元格。



<我试图尽可能多地取出我的自定义代码,我删除了我已经覆盖的函数,并试图尽可能地将事物恢复到原始状态 - 但无济于事。



有一次我在输出日志中看到一条奇怪的消息:
当我们已经有一个消息时,试图设置一个滑动删除单元格....看起来不错。出于某种原因,消息显示的时间更长,我似乎无法记住我当时正在做的事情。



关于可能导致此问题的任何想法或建议?



http://www.youtube .com / watch?v = vCAGzSaOwp4

解决方案

这是iOS 7中无数的错误之一。



出于某种原因,iOS通过删除按钮移动了backgroundView。
您可以通过继承backgroundView并实现派生视图的setFrame函数来解决这个问题,如下所示:

  - (void)setFrame:(CGRect)frame 
{
if([[[[UIDevice currentDevice] systemVersion] compare:@7.0options:NSNumericSearch]!= NSOrderedAscending){
//背景视图涵盖iOS 7上的删除按钮!?!
[super setFrame:CGRectMake(0,frame.origin.y,frame.size.width,frame.size.height)];
} else {
[super setFrame:frame];
}
}

作为旁注:你可以避免需要通过在派生视图中继承和实现layerClass来创建单独的子层:

  +(Class)layerClass 
{
返回[CAGradientLayer类];
}


UPDATE:

Thanks to information from "Evgeny S" I've been able to determine that what is covering up the delete button is the cell background. I had the following function called at the beginning of cell init:

- (void) setupGradientsWithHeight:(int) the_height
{
    CAGradientLayer* gradient = [CAGradientLayer layer];

    gradient.frame  = CGRectMake(self.bounds.origin.x,
                                 self.bounds.origin.y,
                                 self.bounds.size.width,
                                 the_height);

    gradient.colors = [NSArray arrayWithObjects:
                       (id)[UIColor colorWithRed:218.0f/255.0f
                                           green:218.0f/255.0f
                                            blue:220.0f/255.0f
                                           alpha:1.0].CGColor,
                       (id)[UIColor colorWithRed:180.0f/255.0f
                                           green:180.0f/255.0f
                                            blue:184.0f/255.0f
                                           alpha:1.0].CGColor,nil];

    UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];

    [bgview.layer addSublayer:gradient];
    [self setBackgroundView:bgview];
}

The problem is solved by NOT adding the backgroundview. However, I'm wondering how it might be solved while preserving the gradient background for each cell?

One of two things could be happening. When the delete button appears the background view is either being shifted and then back - or its size is being decreased and then back. I tried messing with the width component "self.bounds.size.width" for the gradient frame but I still don't see how that could be affecting things because this function is only called once at cell initialization.

ORIGINAL POST:

I had created an App in Xcode4 under iOS6 SDK - but after loading things up in the new environment (Xcode5 and iOS7 SDK) I ran into a problem. Note that I have resolved all build errors and warnings that came up when making the transition.

I have a tableview with some cells. After entering edit mode, if one clicks the red toggle button to initiate delete mode for a cell - the animation begins and the "Delete" button appears - but only briefly and is then suddenly re-hidden.

Another strange thing I should note is that even while the delete button is covered up - you can still click where it should be and delete the cell.

I've tried to take out as much of my "custom code" as possible, I've removed functions that I had overridden and tried to take things back to an original state as possible - but to no avail.

At one point I had seen a strange message in the output log: "attempting to set a swipe to delete cell when we already have one....that doesn't seem good". For some reason the message is on longer appearing and I can't seem to remember what I was doing at the time.

Any thoughts or recommendations on what might be causing this?

http://www.youtube.com/watch?v=vCAGzSaOwp4

解决方案

This is one of countless bugs in iOS 7.

For some reason the backgroundView is moved by iOS over the delete button. You can work-around this by subclassing your backgroundView and implementing the setFrame function of your derived view like this:

- (void)setFrame:(CGRect)frame
{
    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
        // background view covers delete button on iOS 7 !?!
        [super setFrame:CGRectMake(0, frame.origin.y, frame.size.width, frame.size.height)];
    } else {
        [super setFrame:frame];
    }
}

As a side note: you can avoid the need for a separate sublayer by subclassing and implementing layerClass in your derived view:

+ (Class)layerClass
{
    return [CAGradientLayer class];
}

这篇关于UITableViewCell删除按钮被掩盖了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆