编辑tableView时自定义单元格imageView移到左侧 [英] Custom cell imageView shifts to left side when editing tableView

查看:33
本文介绍了编辑tableView时自定义单元格imageView移到左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tableView,我需要能够从中删除项目,但是,当我将其从编辑模式放回时,自定义单元格中的 imageView 会移到左侧.这是一些相关的代码和图片:

I have a tableView that I need to be able to delete items from, however, when I put it back from editing mode, the imageView from my custom cell gets shifted over to the left side. Here's some relevant code and images:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! NotificationsTableViewCell
    cell.storiesLabel.text = stories[indexPath.row].name
    cell.selectionStyle = UITableViewCellSelectionStyle.None
    cell.shouldIndentWhileEditing = false

    if stories[indexPath.row].notificationBool == true {
        cell.notificationImageView.image = UIImage(named: "notifications_filled.png")
    }
    else {
        cell.notificationImageView.image = UIImage(named: "notifications.png")
    }

    return cell
}

func editFollowedStoriesTableView() {
    if tableView.editing == true {
        tableView.setEditing(false, animated: false)
    }
    else {
        tableView.setEditing(true, animated: false)
    }
}

 func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {

    if(self.tableView.editing){

        return UITableViewCellEditingStyle.Delete

    }
    return UITableViewCellEditingStyle.None

}

如何防止出现第二张图片?非常感谢任何帮助!

How can I prevent the second picture from happening? Any help is very much appriciated!

推荐答案

您有一些相互冲突的自动布局约束.您需要删除 UIImageView 上的以下约束之一:

You have some conflicting auto layout constraints. You need to delete one of the following constraints on the UIImageView:

Width
Leading Space to: Label
Trailing space to: Superview

这里,前导空格和尾随空格约束定义了imageView的宽度.然后你添加了宽度约束来做同样的事情.现在,如果您希望图像视图具有固定宽度,请删除前导空格或尾随空格约束.如果不需要固定宽度,则删除宽度约束.

Here, The leading space and trailing space constraints define the width of the imageView. Then you added the width constraint that does the same thing. Now if you want your image view to have a fixed width delete either the leading space or trailing space constraint. If you don't need to have a fixed width, delete the width constraint.

这篇关于编辑tableView时自定义单元格imageView移到左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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