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