ios - 编辑tableView时自定义单元格imageView移动到左侧

标签 ios swift uitableview uiimageview

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

enter image description here enter image description here

 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

}

如何防止第二张图片的发生? 非常感谢任何帮助!

最佳答案

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

Width
Leading Space to: Label
Trailing space to: Superview

这里,前导空格和尾随空格约束定义了 imageView 的宽度。然后添加宽度约束来执行相同的操作。现在,如果您希望 ImageView 具有固定宽度,请删除前导空格或尾随空格约束。如果不需要固定宽度,请删除宽度约束。

关于ios - 编辑tableView时自定义单元格imageView移动到左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32236984/

相关文章:

ios - 维护 iOS 应用内购买的记录

ios - 在 UIAutomation 中从 UIAElementArray 中按名称获取元素时遇到问题

swift - 向 CoreData 添加自定义类

ios - 如何手动绑定(bind) UITableViewController 类到 UITableView?

objective-c - 在 UITableView 问题的顶部添加额外的单元格

ios - OCMock 版本 3 将无法识别类方法

node.js - iOS Swift Parse-Server 用户登录认证

ios - Swift:在 block 中使用其自身值的变量

ios - 自定义 UITableViewCell 中的 Swift 可变数量的 subview

ios - 需要来自远程 API 的日期