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

编程入门 行业动态 更新时间:2024-10-27 03:43:41
本文介绍了编辑tableView时自定义单元格imageView移到左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:40:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   移到   单元格   编辑   tableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!