Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置动画时透明UITableViewCell闪烁背景_Ios_Objective C_Uitableview_Ios7 - Fatal编程技术网

Ios 设置动画时透明UITableViewCell闪烁背景

Ios 设置动画时透明UITableViewCell闪烁背景,ios,objective-c,uitableview,ios7,Ios,Objective C,Uitableview,Ios7,我有一个带有自定义背景色的UIViewController。在它的顶部有一个UITableView,带有半透明的UITableView单元格(白色,不透明度为0.5) 我一直在抱怨的问题是,在iOS 7中,当你有一个半透明背景的UITableViewCell时,你试图删除/插入/移动行(因此依赖动画效果)整个UITableView,其单元格仅闪烁0.1秒,并将单元格背景设置为更透明的背景。这很烦人 我正在做的唯一一件事是使用以下设置self.view的背景色: self.view.backgro

我有一个带有自定义背景色的
UIViewController
。在它的顶部有一个
UITableView
,带有半透明的
UITableView单元格
(白色,不透明度为0.5)

我一直在抱怨的问题是,在iOS 7中,当你有一个半透明背景的
UITableViewCell
时,你试图删除/插入/移动行(因此依赖动画效果)整个
UITableView
,其单元格仅闪烁0.1秒,并将单元格背景设置为更透明的背景。这很烦人

我正在做的唯一一件事是使用以下设置
self.view
的背景色:

self.view.backgroundColor = [UIColor colorWithRed:0.4 green:0.5 blue:0.7 alpha:1];
并将单元格的背景色设置为:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
}
下面是一个gif显示问题:

下面是一个超级简单的项目:

请帮我解决这个可笑的问题!:P

  • 创建UITableViewCell的子类(例如命名为:CustomCell),并重写CustomCell.m中的方法:

    - (id)initWithCoder:(NSCoder *)aDecoder{
        self = [super initWithCoder:aDecoder];
        if(self){
            // Initialization code
            [self setBackgroundColor:[UIColor clearColor]];
            UIView * bgView = [[UIView alloc] initWithFrame:self.frame];
            [bgView setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.5]];
            [self addSubview:bgView];
        }
        return self;
    }
    
  • 删除MasterViewController.m中的willDisplayCell方法

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    
  • 更改MasterViewController.m中的
    cellforrowatinexpath
    方法

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    
  • 在情节提要中更改单元格的类类型

  • 试试看:D


    UITableView的背景颜色是什么?如果您已经设置了一个,请尝试在xib/故事板中将其设置为“清晰”(或您选择的任何颜色)。通常在iOS7中,它被设置为“default”,这是大多数问题的原因。看起来这并不重要。我尝试将
    self.view
    (即表视图)的背景色设置为
    [UIColor clearColor]
    ,还尝试将表视图嵌入
    UIView
    (视图控制器的主视图)并将此视图的背景色设置为clear。不行,哦,好的。然后,您可能需要通过对UITableViewCell的setSelected()属性进行子类化来覆盖它。或者至少使用backgroundView属性而不是backgroundColor。我爱你!它就像一个闪亮的符咒。为什么我们需要添加自定义视图作为背景视图?可能是因为
    UITableViewCell
    backgroundView
    backgroundColor
    属性就是这样工作的,我们不能做任何事情来改变这种行为?谢谢你,伙计!另外,GIF的+1:-)它在iOS6中运行良好,我们只设置单元格的背景视图或背景颜色。实际上,我不太清楚为什么在iOS7中更新时单元格会闪烁…:DHey我有完全相同的问题,但我没有使用故事板。那么我可以在initWithFrame:cellReuseIdentifier中使用编码器进行初始化吗?如果我将子视图添加到单元格中,它不会位于文本标签上方吗?因为我无法看到我的文本标签?@user1010819(1)当xib/情节提要加载视图时,框架将调用initWithCoder。不要手动调用initWithCoder!(2) 如果看不到标签,可以在addSubview:…之后调用[self.view sendSubviewToBack:bgView]。。。试试看!