UITableViewCell自定义编辑视图

瑞安

我正在尝试替换单元格的默认编辑模式行为。

我不希望出现带有左附件视图线的红色圆圈。

进入编辑模式后,我需要它向左移动内容视图并显示我的删除按钮。

到目前为止,我所拥有的(自定义UITableViewCell)覆盖了:

-(void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    /* don't call super */
//    [super setEditing:editing animated:animated];
    _isEditing = editing;

    CGFloat newContentViewX = 0.0f;
    UIColor *newDeleteButtonColor = [UIColor clearColor];

    if ( _isEditing )
    {
        newContentViewX = -40.0f;
        newDeleteButtonColor = [UIColor redColor];
    }

    if ( animated )
    {
        [UIView animateWithDuration:0.5f
                              delay:0.0f
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^
         {
             self.contentView.x = newContentViewX; //change frame.origin.x
             _deleteButton.backgroundColor = newDeleteButtonColor;
         }
                         completion:nil];
    }
    else
    {
        self.contentView.x = newContentViewX; //change frame.origin.x
        _deleteButton.backgroundColor = newDeleteButtonColor;
    }
}

-(BOOL) editing
{
    return _isEditing;
}

这是结果: setEditing:NO setEditing:YES

上面的代码很棒!直到开始滚动并且contentview重置。回到第一张图片。编辑标志未保留我的contentview框架更改。

我添加了这一行:

[cell setEditing:_tableView.isEditing animated:NO];

在cellForRowAtIndexPath中,虽然它正在正确调用并设置编辑模式,但我的contentview仍处于原始位置,而不是更新

简短的youtube视频解释问题:Youtube链接

还有其他人有这个问题吗?

亚历克斯·库里洛(Alex Curylo)

您的问题是UITableView正在“有用”地设置从cellForRowAtIndexPath返回的单元格的适当状态布局。

解决此问题的最简单方法是在您的单元格类中覆盖-layoutSubviews。

- (void)layoutSubviews
{
   if (self.editing)
  {
     CGRect bounds = self.bounds;
     // do your custom layout
  }
  else
    [super layoutSubviews];
}

那应该可以使事情分类。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章